I want to add a space and shade between each element in listview.
How the tool is drawn xml?
Create a xml file Shadow.xml in Android drawable folder.
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape
android:shape="rectangle">
<solid android:color="#android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="6dp" android:left="6dp" android:bottom="9dp">
<shape
android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
Uasge: Set the shadow with background of Layout. Use divider property to set the space between each element in listview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center"
android:background="#drawable/shadow"
android:orientation="vertical">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="20px"
android:divider="#android:color/darker_gray"
android:layerType="software"
/>
</LinearLayout>
MainActivity:
ListView listView = FindViewById<ListView>(Resource.Id.listview);
string[] s = new string[] { "a", "b", "c","d","e","f","g","h","i","j","k" };
ArrayAdapter<string> arrayAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, s);
listView.Adapter = arrayAdapter;
Related
I have a recyclerview inside of a viewholder item that is for displaying up to 5 images nicely along with some other text. it's working pretty good except that the images are mega tiny looking, I'm not sure where I'm going wrong.
the main viewholder item layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="14dp">
<TextView
android:id="#+id/feedItem_txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_marginTop="14dp"
android:textColor="#color/dark_gray"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/feedItem_rvImageGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<View
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="15dp"
android:background="#color/very_light_gray"/>
</LinearLayout>
</LinearLayout>
the image grid viewholder item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/feedItemImage_ivImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
</LinearLayout>
the code I'm using to bind the grid to the recyclerview
_layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.Vertical);
_feedItemImageAdapter = new FeedItemImageAdapter(_imageUrlsVisible, _imageUrlsFull);
_rvImageGrid.SetAdapter(_feedItemImageAdapter);
_rvImageGrid.SetLayoutManager(_layoutManager);
not sure what else you'd like to see, let me know if I need to provide more code samples, I'm at a lost on what I'm doing wrong.
One possibility is that your image size itself is small.
I tried to reproduce this question by using pictures of different sizes,when the image grid viewholder item is as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/feedItemImage_ivImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
</LinearLayout>
The result is :
But we can adjust the parent properties of the ImageView to
android:layout_width="match_parent"
android:layout_height="match_parent"
So when we use the following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/feedItemImage_ivImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
</LinearLayout>
Now,we will find the image will be adjusted to the proper size,but at the same time,the picture is distorted and blurry.
I have a problem. I want to create 3 FrameLayouts below each other, so I created this code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#071c3f"
android:orientation="vertical">
<FrameLayout
android:id="#+id/ActionBarContainer"
android:layout_width="match_parent"
android:layout_height="75dp"/>
<FrameLayout
android:id="#+id/LayoutContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<FrameLayout
android:id="#+id/ToolBarContainer"
android:layout_width="match_parent"
android:layout_height="40dp"/>
</LinearLayout>
But this only shows the first 2 FrameLayouts and the thirth FrameLayout isn't visible. What am I doing wrong?
It's because your 2nd view is taking up all the remaining screen space (it's using "match_parent") after the first FrameLayout has been placed.
It looks like you're wanting a fixed header and footer along with a content view that fills the remaining space. So, if that assumption is true, I think this is what you are after...notice the usage of the "layout_weight" attribute and how the content view is assigned a "1" whereas the others are assigned a "0"...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#071c3f"
android:orientation="vertical">
<FrameLayout
android:id="#+id/ActionBarContainer"
android:background="#color/red"
android:layout_width="match_parent"
android:layout_height = "75dp"
android:layout_weight = "0"/>
<FrameLayout
android:id="#+id/LayoutContainer"
android:background="#color/blue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight = "1"/>
<FrameLayout
android:id="#+id/ToolBarContainer"
android:background="#color/green"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight = "0"/>
</LinearLayout>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#ffff0000</color>
<color name="blue">#ff0000ff</color>
<color name="green">#ff00ff00</color>
</resources>
Screenshot
Hope this helps!
Followed the guide from:
https://us.v-cdn.net/5019960/uploads/FileUpload/72/535f17b6e5737cdf0a12e105218ec7.txt
facing this issue in layout main.axml file that The element LinearLayout has an invalid child multiselectspinner.multiselectspinner.
My main.axml is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<MultiSelectSpinnerExample.MultiSelectSpinner
android:id="#+id/my_spin"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I have to give my MaterialSpinner the following border:
I have the following MaterialSpinner
<fr.ganfra.materialspinner.MaterialSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner"
app:ms_arrowColor="#000000"
app:ms_arrowSize="16dp"
app:ms_floatingLabelColor="#A9A9A9"
app:ms_floatingLabelText="Избор на група"
app:ms_hint="Избор на група"
app:ms_hintColor="#000000"
android:padding="10dp"
android:layout_gravity="center"
android:background="#drawable/material_spinner_border"/>
material_spinner_border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- View background color -->
<solid
android:color="#000000" >
</solid>
<!-- View border color and width -->
<stroke
android:width="1dp"
android:color="#000000" >
</stroke>
<!-- The radius makes the corners rounded -->
<corners
android:radius="2dp" >
</corners>
</shape>
When I run the app the border doesn't appear on screen
How to put a border around MaterialSpinner Xamarin.Android?
Set your MaterialSpinner ms_arrowColor color as white to hide the arrow:
<fr.ganfra.materialspinner.MaterialSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner"
app:ms_floatingLabelColor="#A9A9A9"
app:ms_floatingLabelText="Избор на група"
app:ms_hint="Избор на група"
app:ms_hintColor="#000000"
app:ms_arrowColor="#ffffff"
app:ms_arrowSize="16dp"
android:background="#drawable/material_spinner_border"
android:layout_margin="5dp"
/>
Add your arrow image to your project, for example:
Then, modify your material_spinner_border like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<stroke android:width="3dp" android:color="#000000" />
<corners android:radius="4dp" />
<padding android:bottom="0dp" android:left="3dp" android:right="3dp" android:top="0dp" />
</shape>
</item>
<item >
<bitmap android:gravity="center|right" android:src="#drawable/myarrow" />
</item>
</layer-list>
</item>
</selector>
Effect.
Update:
Set spinner background after set the Spinner adapter will solve this issue:
string[] ITEMS = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6" };
var adapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleSpinnerItem, ITEMS);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
var spinner = FindViewById<MaterialSpinner>(Resource.Id.spinner);
spinner.Adapter = adapter;
spinner.Background = Drawable.CreateFromXml(Resources, Resources.GetXml(Resource.Drawable.material_spinner_border));
Here is a picture what it looks like:
I forgot to tell you that my backgroung is dark if it matters
How to add text color to ListView ?
The background is white for Layout and I need the text color to be darkgray or black.
--UI
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ListView1" />
</LinearLayout>
-- code :
listV= FindViewById<ListView>(Resource.Id.ListView1);
itemlist = new List<string>();
itemlist.Add("item1");
itemlist.Add("item2");
itemlist.Add("item3");
itemlist.Add("item4");
itemlist.Add("item5");
itemlist.Add("item6");
itemlist.Add("item7");
itemlist.Add("item8");
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist);
listV.Adapter = adapter;
Thanks
Create a layout file containing the textview you want with textSize, textStyle, color etc preferred by you and then use it with the ArrayAdapter.
e.g. mytextview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tview"
android:textColor="#color/yourColor"
android:padding="5sp"
android:layout_width="fill_parent"
android:background="#drawable/rectgrad"
android:singleLine="true"
android:gravity="center"
android:layout_height="fill_parent"/>
and then use it with your ArrayAdapter as usual like
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, R.layout.mytextview, itemlist);