<layer-list>后台禁用android:padding setting </layer-list>

时间:2014-10-04 15:46:01

标签: android layer-list

我有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>

我错过了什么?

1 个答案:

答案 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>