2012-02-14 69 views
12

我有用于的LinearLayout背景 一个形象比方说像有20X100 PX 我想要只在X轴的图像重复......像这样的东西在CSSAndroid的图像背景重复

background-repeat:repeat-x; 

该LinearLayout中是有点大(1024×680像素),所以我的形象将覆盖整个宽度,但仅在顶部(580像素高度的其余部分将是透明的) 我希望我是清楚的 感谢

+0

做ü知道draw9patch图像? – 2012-02-14 14:56:34

回答

53

尝试使用android:tileMode

在绘制文件夹中创建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" > 
+0

不工作,LinearLayout没有'android:tileMode' – Sadegh 2013-08-28 15:44:09

+3

@Sirlate请检查上面编辑的解决方案。 – Zeba 2013-08-29 07:20:42

+1

这是公认的答案! – offset 2014-11-12 09:47:15