Android形状自定义矩形

时间:2014-10-31 17:34:14

标签: android shape

我有这个画一个矩形。

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#00000000" />
    <stroke android:width="1dp" android:color="#ffffff" android:dashWidth="0dp" android:dashGap="0dp" />
</shape>

但我想在顶部和底部只有2条水平线。我们如何实现这一目标?

Iwant to achieve no 2

1 个答案:

答案 0 :(得分:0)

我从这个Open-sided Android stroke?

得到了线索

现在有效。

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
    <item android:top="-1dp" android:right="-1dp" android:left="-1dp">
      <shape>
            <solid android:color="@android:color/transparent" />
            <stroke android:width="1dp" android:color="#ffffff" />
      </shape>
    </item>

    <item android:bottom="-1dp" android:right="-1dp" android:left="-1dp">
      <shape>
            <solid android:color="@android:color/transparent" />
            <stroke android:width="1dp" android:color="#ffffff" />
      </shape>
    </item>    
</layer-list>