I have a ListView
with custom items layout and custom background.
The problem is android:padding
value seems to be ignored after I switched background drawable 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>
drawable/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. 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?
Wrapping <layer-list>
in a <selector>
has solved the issue:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With