2012-02-14 70 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