对于线性布局,我希望在背景中具有渐变和平铺(重复)图像。我已经将形状 xml 设置为背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:angle="90"
android:endColor="@color/color1"
android:startColor="@:color/color2">
</gradient>
</shape>
如何添加平铺背景图像?
查看LayerLists
.
以下是一个 XML 可绘制对象,名为myBackground.xml
, 放在res/drawable
。
将其设置为背景View
您想要为其设置渐变和平铺背景。
在下面的示例中,平铺图像将位于渐变的顶部,因为它是稍后在LayerList
- 显然,如果它位于顶部,您需要在 png 图像图块上设置一些透明度(您可以在图像编辑应用程序中设置它,例如 GIMP 或 Photoshop)。
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:type="radial" android:gradientRadius="500"
android:startColor="#17568A"
android:endColor="#494C4F" />
</shape>
</item>
<item>
<bitmap
android:src="@drawable/tile_classy_fabric"
android:tileMode="repeat" />
</item>
</layer-list>
“tile_classy_fabric”指的是我的文件中名为“tile_classy_fabric.png”的文件res/drawable
文件夹(250px 方形,因为它是可平铺的 - 我们不需要它太大)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)