Android - 具有特定笔画的XML形状

时间:2014-01-26 09:32:52

标签: android android-xml

我想创建一个XML矩形形状,其规格如下:

  

笔划/边框顶部= 0 dp
  中风/边界左= 3 dp
  笔划/边框底部= 0 dp
  中风/右边界= 3 dp

到目前为止我所拥有的是:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <gradient android:type="linear"
        android:angle="90"
        android:startColor="#ff5588"
        android:centerColor="#ff8855"
        android:endColor="#ff5588" />

    <stroke android:width="3dp"/> <!-- the problem is here -->
</shape>

但是你知道<stroke>标签没有为我的目的提供任何相关的选项。任何人都可以帮助我如何实现这种形状。谢谢

1 个答案:

答案 0 :(得分:1)

您可以尝试使用下面的layer-list

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#THE_BORDER_COLOR"/>
        </shape>

    </item>

    <item android:left="3dp" android:right="3dp">
        <shape
            android:shape="rectangle">

            <gradient
                android:type="linear"
                android:angle="90"
                android:startColor="#ff5588"
                android:centerColor="#ff8855"
                android:endColor="#ff5588"/>
        </shape>
    </item>

</layer-list>