为什么你不能使用 BitmapDrawable 这里有一个示例代码:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/drawable_resource"
android:gravity="center"
android:tileMode="repeat"/>
- 只需替换为您的可绘制 src 名称并将其保存为 .xml 文件。
- 将文件存储在 res/drawable 目录中。
- 分配引用
android:background="@drawable/drawable_resource"
,它将被平铺。
例子:
<LinearLayout
android:background="@drawable/drawable_resource"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LineatLayout
这是一个完整的Bitmap Drawable模板,您可以根据需要选择属性值。
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@[package:]drawable/drawable_resource"
android:antialias=["true" | "false"]
android:dither=["true" | "false"]
android:filter=["true" | "false"]
android:gravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
"fill_vertical" | "center_horizontal" | "fill_horizontal" |
"center" | "fill" | "clip_vertical" | "clip_horizontal"]
android:tileMode=["disabled" | "clamp" | "repeat" | "mirror"] />
你可以在这里找到相同的文档寻找 XML Bitmap。