android 竖条背景绘制,android – 如何使用形状创建带条纹的背景,而不是图像
时间: 2023-11-22 07:53:46 浏览: 28
您可以使用ShapeDrawable来创建带条纹的背景,而不是使用图像。下面是一个示例代码:
1. 创建一个XML文件作为形状定义,例如 stripe_bg.xml:
```xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size android:width="10dp" android:height="10dp" />
<gradient
android:type="linear"
android:startColor="#ffffff"
android:endColor="#ffffff"
android:angle="45"/>
<stroke
android:width="1dp"
android:color="#000000"/>
</shape>
```
这个XML定义了一个10dp * 10dp 的矩形,带有45度角度的白色线性渐变和1dp的黑色描边。
2. 在需要使用该形状的视图的XML布局文件中,将背景设置为stripe_bg.xml:
```xml
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/stripe_bg" />
```
这将在视图的背景中创建带有条纹的效果。
希望这可以帮助您创建自定义的条纹背景。