список элементов списка пробел xamarin android - PullRequest
0 голосов
/ 01 апреля 2020

Я хочу добавить пробел и тень между каждым элементом в просмотре списка.

Как нарисован инструмент xml?

enter image description here

1 Ответ

1 голос
/ 02 апреля 2020

Создать xml файл Shadow.xml в папке Android drawable.

<?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: установить тень на фоне макета. Используйте свойство divider, чтобы установить расстояние между каждым элементом в просмотре списка.

<?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;

enter image description here

...