2012-07-20 125 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" />