Android的背景渐变和平铺图像 [英] Android background with gradient and tiled image
问题描述
对于一个LinearLayout中,我希望有一起在背景平铺(重复)的图像的渐变。我已经有一个形状XML设置为背景
For a linearLayout, I want to have a gradient along with a tiled (repeated) image in the background. I already have a shape xml set as the background
<?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>
我如何添加一个平铺的背景图片?
How do I add a tiled bg image?
推荐答案
查看 LayerLists
。
下面是一个XML绘制,名为 myBackground.xml
,放在 RES /绘制
。
它设置为视图的背景
要设置渐变和瓷砖背景。
The following is an XML drawable, called myBackground.xml
, placed in res/drawable
.
Set it as the background of the View
you want to set a gradient and tiled background for.
在下面的例子中,平铺图像将在坡度的顶部,因为它是在后面指定的 LayerList
- 很明显,如果这是在上面,你会需要对PNG图像平铺一些透明度(你可以把这个在图像编辑应用程序,像GIMP或Photoshop)。
In the example below, the tiled image will be on top of the gradient, because it is specified later in the LayerList
- obviously if it's on top, you'll need some transparency on the png image tile (you can set this in an image editing application, like GIMP or 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 /绘制
文件夹中(250像素正方形文件,因为它是平铺 - 我们不需要它超大)。
"tile_classy_fabric" refers to a file called "tile_classy_fabric.png" in my res/drawable
folder (250px square, as it's tileable - we don't need it super large).
这篇关于Android的背景渐变和平铺图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!