我只想创建一个自定义背景,但我不知道如何使用 xml 而不是图像来做到这一点。
这是 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@layout/ui_shape"
tools:context="${relativePackage}.${activityClass}" >
</RelativeLayout>
and I want like this. Is it possible to create xml like the required image?
这是 ui_shape
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
>
<item>
<rotate
android:fromDegrees="45">
<shape
android:shape="line" >
<stroke android:color="@color/ui" android:width="1dp" />
<solid
android:color="@color/ui" />
</shape>
</rotate>
</item>
</layer-list>
和颜色
<color name="ui">#0095A0</color>
这就是我得到的
有人有什么想法吗?
我知道我迟到了,但如果有人到达这里,这是我的解决方案:
1)在Photoshop或任何其他程序中创建一条小对角线,它应该看起来像这样
*
*
*
*
2) 在 android studio 中创建以下 XML 可绘制对象,其中“@drawable/diagonal_line”是前面提到的图像:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/diagonal_line"
android:tileMode="repeat"
android:dither="true"
>
</bitmap>
这个位图可绘制的作用是采用单对角线并在选定的视图上重复它。
3) 现在使用该 XML 可绘制对象作为视图背景,作为示例,这就是我使用它的方式,其中“@drawable/tiled_background”是步骤 2 中的 XML:
<View
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@drawable/tiled_background"/>
这是结果:
我希望这对任何人都有帮助。快乐编码!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)