<layer-list> background disables android setting: add
I have one ListView
with custom item layout and custom background. The problem is that the value android:padding
seems to be ignored after switching the background from <shape>
to <layer-list>
.
layout / list _item.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_list_item_bill"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp">
. . .
</LinearLayout>
fetch / list _item_background.xml
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="@dimen/corner_radius" />
<stroke android:width="1dp" android:color="@color/blue" />
</shape>
The above works as expected. The padding disappears when I change drawable/list_item_background.xml
to
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/white"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="@dimen/corner_radius" />
<stroke android:width="1dp" android:color="@color/blue" />
</shape>
</item>
</layer-list>
What am I missing?
+3
source to share
1 answer
Wrapping <layer-list>
in <selector>
solved the problem:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<solid android:color="@color/white"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="@dimen/corner_radius" />
<stroke android:width="1dp" android:color="@color/blue" />
</shape>
</item>
</layer-list>
</item>
</selector>
+2
source to share