2011-06-06 105 views
4

我做了一個帶有背景圖像,PNG的線性佈局...我不知道如何將它顯示到佈局(和居中)保持比例...這裏是代碼線性佈局的背景圖像尺寸不是很好

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background"> 

顯然圖像具有相同的高度和寬度的顯示...任何幫助?在此先感謝

= .4.S。=

+0

是圖像被顯示出來歪斜(錯誤的比例),不填充的LinearLayout的整個區域的問題,不居中,或者一些三者的結合? – plainjimbo 2011-06-06 20:48:42

+0

好吧,圖像填充整個區域並居中,但比例錯誤,因爲它錨定在佈局上... – Erenwoid 2011-06-06 20:54:39

回答

0

如果你不想被拉伸你的圖片,則可以使用BitmapDrawable重力爲我們樹立代替PNG的。
參考文檔:Bitmap

8

謝謝大家^^我這樣解決:

<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 


    <ImageView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/background" 
     android:layout_gravity="center"/> 


    <ListView android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:divider="#FFFFFF" 
     android:layout_weight="2" 
     android:drawSelectorOnTop="false" 
     android:layout_gravity="center"/> 

</FrameLayout>