Android:使用可绘制形状的多虚线背景
有没有一种方法可以使用可绘制的形状或类似的东西来为视图创建虚线背景 理想情况下,我想要这样的东西(当然有不同的颜色)。忽略蓝色边框,我只希望红线作为视图的背景重复 以下是一个示例:Android:使用可绘制形状的多虚线背景,android,android-shapedrawable,Android,Android Shapedrawable,有没有一种方法可以使用可绘制的形状或类似的东西来为视图创建虚线背景 理想情况下,我想要这样的东西(当然有不同的颜色)。忽略蓝色边框,我只希望红线作为视图的背景重复 以下是一个示例: <?xml version="1.0" encoding="UTF-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</item>
<item
android:top="-400dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="10dp"
android:dashGap="10dp" />
</shape>
</item>
<item
android:top="-300dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="10dp"
android:dashGap="10dp" />
</shape>
</item>
<item
android:top="-200dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="10dp"
android:dashGap="10dp" />
</shape>
</item>
<item
android:top="-100dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="10dp"
android:dashGap="10dp" />
</shape>
</item>
<item
android:top="0dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="10dp"
android:dashGap="10dp" />
</shape>
</item>
<item
android:top="100dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="10dp"
android:dashGap="10dp" />
</shape>
</item>
<item
android:top="200dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="10dp"
android:dashGap="10dp" />
</shape>
</item>
<item
android:top="300dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="10dp"
android:dashGap="10dp" />
</shape>
</item>
<item
android:top="400dp">
<shape android:shape="line">
<stroke
android:width="2dp"
android:color="#ff0000"
android:dashWidth="10dp"
android:dashGap="10dp" />
</shape>
</item>
</layer-list>
屏幕截图:
本例中有九条虚线。通过相对于中心线上下移动每个新行,可以放置任意多的内容,中心线具有android:top=“0dp”
属性
以下是有关的详细信息。使用@drawable图像如何?我只想能够重复使用像///////这样的背景,而无需使用.9补丁或图像环。是的,我的意思是在没有图像的情况下平铺背景。看起来我必须使用图像解决方案。理想情况下,任何通过XML定义的东西,我现在只使用一个图像,而是使用一个可以正确缩放的绘图工具