gpt4 book ai didi

android - 后台禁用android :padding setting

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:24:38 26 4
gpt4 key购买 nike

我有一个 ListView具有自定义项目布局和自定义背景。问题是android:padding在我从 <shape> 切换背景可绘制对象后,值似乎被忽略了至 <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>

以上按预期工作。当我更改 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>

我错过了什么?

最佳答案

包装 <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>

关于android - <layer-list> 后台禁用android :padding setting,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26194416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com