我有一个用于LinearLayout背景的图片, 假设该图片大小为20x100像素, 我想让这张图片仅在x轴上重复使用...就像css中的这样
background-repeat:repeat-x;
LinearLayout很大(1024 x 680像素),所以我的图像将覆盖整个宽度,但仅在顶部(其余580像素高度将是透明的)。 希望我表达清楚了。 谢谢
我有一个用于LinearLayout背景的图片, 假设该图片大小为20x100像素, 我想让这张图片仅在x轴上重复使用...就像css中的这样
background-repeat:repeat-x;
LinearLayout很大(1024 x 680像素),所以我的图像将覆盖整个宽度,但仅在顶部(其余580像素高度将是透明的)。 希望我表达清楚了。 谢谢
尝试使用 android:tileMode
在drawable文件夹中创建background.xml
,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/bg"
android:tileMode="repeat" />
然后在您的布局XML中使用它:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
LinearLayout
没有 android:tileMode
。 - Sadegh您可以使用android:background作为9patch图像来自动拉伸。
{{link1:Android Dev网站上的9patch}}