2012-07-20 123 views
0

我需要STRETCH時的背景圖像在我的應用程序佈局,Android的佈局圖像填充寬度

請注意,在我的佈局的黃色背景不streched

enter image description here

如何完成這[黃色條形圖填充父項]?

還請注意,藍色的佈局不是整個屏幕的寬度,怎麼樣?

代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingLeft="8dp" 
     android:paddingRight="8dp" 
     android:id="@+id/myfragment"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_weight="1" 
      android:background="#0000FF"> 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/titlebar" /> 

    </LinearLayout> 

    <ListView android:id="@id/android:list" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:drawSelectorOnTop="false"/> 




</LinearLayout> 

非常感謝!

回答

2

這就是爲什麼你的LinearLayout(藍色)不配合整個屏幕寬度

android:paddingLeft="8dp" 
android:paddingRight="8dp" 

你需要改變這種情況的原因。改爲爲內部佈局設置保證金(左側和右側)。

而不是圖像的查看您可以設置第二linearlyout的背景直接

android:background="@+id/imageView1" 

櫃面您要使用的圖像視圖,而不是

 <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="fill_parent" 
     android:layout_height="50dp" 
     android:scaleType="fitXY" 
     android:src="@drawable/titlebar" />