Reputation: 61
I want to add a space and shade between each element in listview.
How the tool is drawn xml?
Upvotes: 0
Views: 205
Reputation: 10978
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;
Upvotes: 1