我有ListView
个自定义项目布局和自定义背景。
我将背景绘制从android:padding
切换为<shape>
后似乎忽略了<layer-list>
值。
布局/ 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>
抽拉/ 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>
以上工作符合预期。将drawable/list_item_background.xml
更改为
<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>
我错过了什么?
答案 0 :(得分:3)
在<layer-list>
中结束<selector>
已解决了问题:
<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>