Android:如何从图案创建背景? [英] Android: how to create a background from pattern?
问题描述
我有一个图案(.png 图像 4x4px),必须用它填充布局.
I have a pattern (.png image 4x4px) and have to fill the layout with it.
有人知道怎么做吗?
如果我只是选择可绘制对象作为图像的背景,它会被拉伸;相反,它需要沿 x 和 y 轴重复.
If I simply select the drawable as a background the image, it is stretched; instead it needs to be repeated along the x and y axis.
推荐答案
这里是一个非常好的解释:
将您的back.png"图像放在drawable"文件夹中.然后像这样创建一个可绘制的backrepeat.xml":
Put your "back.png" image on "drawable" folder. Then create a drawable "backrepeat.xml" like that:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/back"
android:tileMode="repeat" />
在你的布局中,添加 android:background="@drawable/backrepeat"
:
In your layout, add android:background="@drawable/backrepeat"
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/MainLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/backrepeat">
</LinearLayout>
与许多 Android 良好做法/实用技巧一样,它可以追溯到 Romain Guy.
As is the case with many Android good practices/handy tricks, it can be traced back to Romain Guy.
这篇关于Android:如何从图案创建背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!