【发布时间】:2010-06-21 20:05:32
【问题描述】:
我想要一个带有两种颜色边框轮廓的shape 元素。我可以使用solid 元素制作单一颜色的轮廓,但这仅允许我画一条线。我尝试在我的形状中使用两个 stroke 元素,但这也不起作用。
有没有办法在一个形状中绘制一个形状或在我的形状周围画两条线(顺便说一句,它有圆角)。
【问题讨论】:
我想要一个带有两种颜色边框轮廓的shape 元素。我可以使用solid 元素制作单一颜色的轮廓,但这仅允许我画一条线。我尝试在我的形状中使用两个 stroke 元素,但这也不起作用。
有没有办法在一个形状中绘制一个形状或在我的形状周围画两条线(顺便说一句,它有圆角)。
【问题讨论】:
我发现<layer-list> 是最好的方法。像这样:
<?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 xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="3dp"
android:color="#000000" />
</shape>
</item>
<item
android:bottom="1dp"
android:left="8dp"
android:right="8dp"
android:top="1dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="2dp"
android:bottomRightRadius="2dp"
android:topLeftRadius="2dp"
android:topRightRadius="2dp" />
<solid android:color="@android:color/white" />
<stroke
android:width="1dp"
android:color="#BDBDBD" />
</shape>
</item>
</layer-list>
然后,您需要在 listView 行布局上设置适当的边距,但效果非常好。
【讨论】:
所以我有一个解决方法,但它很难看。解决方法是将我的元素包装在另一个容器元素中。即
<RelativeLayout ... android:background="@drawable/outer">
<ListView ... android:background="@drawable/inner" />
</RelativeLayout>
【讨论】: