我有一个4x4像素的图案(.png图片),需要用它来填充布局。
请问有人知道如何做吗?
如果我简单地将可绘制对象选择为背景图片,那么图片会被拉伸;相反,它需要沿着x和y轴重复出现。
我有一个4x4像素的图案(.png图片),需要用它来填充布局。
请问有人知道如何做吗?
如果我简单地将可绘制对象选择为背景图片,那么图片会被拉伸;相反,它需要沿着x和y轴重复出现。
这里有一个非常好的解释:
将你的 "back.png" 图像放在 "drawable" 文件夹中。然后创建一个名为 "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。