我有一个带有渐变的形状,我将其用作ListView
项目之间的分隔符。我把它定义如下:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ccd0d3"
android:centerColor="#b6babd"
android:endColor="#ccd0d3"
android:height="1px"
android:angle="0" />
</shape>
我想在渐变的两边添加6个像素的填充,这样它就不会从屏幕的边缘延伸到另一个边缘。
然而,无论我将android:left="6px"
和android:right="6px"
放在哪里,它似乎都不起作用。我可以把它放在<shape>
元素、<gradient>
元素中,也可以放在<shape>
的一个单独的<padding>
子元素中,它不会改变任何东西。
如何在列表分隔符的左侧和右侧添加填充?
发布于 2009-10-26 06:57:33
一种解决方案似乎是用另一个指定适当填充的drawable“包装”我的drawable。
例如,list_divider.xml
将为:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="6dp"
android:right="6dp"
android:drawable="@drawable/list_divider_inner" />
</layer-list>
然后list_divider_inner.xml
将成为原始的可绘制部分:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#ccd0d3"
android:centerColor="#b6babd"
android:endColor="#ccd0d3"
android:height="1px"
android:angle="0" />
</shape>
这会导致两个文件指定一个简单的分隔符。我不知道有没有办法只用一个文件就能做到。
发布于 2010-08-28 08:46:17
我想你可以这样组合它:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="6dp"
android:right="6dp">
<shape android:shape="rectangle">
<gradient android:startColor="#ccd0d3"
android:centerColor="#b6babd"
android:endColor="#ccd0d3"
android:height="1px"
android:angle="0"/>
</shape>
</item>
</layer-list>
发布于 2012-12-07 02:19:07
另一种使用inset的解决方案:
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="6dp"
android:insetRight="6dp" >
<shape
android:shape="rectangle">
<gradient
android:startColor="#ccd0d3"
android:centerColor="#b6babd"
android:endColor="#ccd0d3"
android:height="1px"
android:angle="0" />
</shape>
</inset>
https://stackoverflow.com/questions/1622364
复制相似问题