Android:如何从模式创build背景?

我有一个模式(.png图像4x4px),必须填写它的布局。

有谁知道如何做到这一点?

如果我简单地selectdrawable作为背景的图像,它会被拉伸; 相反,它需要沿x和y轴重复。

这是一个非常好的解释:

把你的“back.png”图像放在“drawable”文件夹中。 然后像这样创build一个可绘制的“backrepeat.xml”:

<?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"

 <?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。