安卓图片背景重复

14

我有一个用于LinearLayout背景的图片, 假设该图片大小为20x100像素, 我想让这张图片仅在x轴上重复使用...就像css中的这样

background-repeat:repeat-x;

LinearLayout很大(1024 x 680像素),所以我的图像将覆盖整个宽度,但仅在顶部(其余580像素高度将是透明的)。 希望我表达清楚了。 谢谢


你是否了解绘制9patch图像? - Padma Kumar
2个回答

55

尝试使用 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

0

您可以使用android:background作为9patch图像来自动拉伸。

{{link1:Android Dev网站上的9patch}}


6
这不是所问问题的答案。 - maclir

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接