Android:如何从模式创建背景? [英] Android: how to create a background from pattern?
问题描述
我有一个图案(.png图像4x4px),并且必须用它填充布局。
有谁知道如何做到这一点?
如果我简单地选择drawable作为背景的图像,那么它是被拉伸的;而是需要沿着x轴和y轴重复。
这里是一个非常好的解释:
将您的back.png图像放在drawable文件夹上。然后创建一个可绘制的backrepeat.xml:
<?xml version =1.0encoding =utf- 8\" >?;
<位图xmlns:android =http://schemas.android.com/apk/res/android
android:src =@ drawable / back
android:tileMode = 重复/>
在您的布局中,添加 android:background =@ drawable / backrepeat
:
<?xml version =1.0encoding =utf-8?> ;
< LinearLayout
android:id =@ + id / MainLayout
xmlns:android =http://schemas.android.com/apk/res/android$ b $
android:layout =
< / LinearLayout>
与许多Android的良好做法/方便的技巧一样,它可以追溯到Romain Guy 。
I have a pattern (.png image 4x4px) and have to fill the layout with it.
Does anyone know how to do this?
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.
Here is a really nice explanation:
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" />
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>
As is the case with many Android good practices/handy tricks, it can be traced back to Romain Guy.
这篇关于Android:如何从模式创建背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!