2013-02-05 24 views
1

我想將imageview和listview放在兩個單獨的相對佈局中,但是當我將圖像添加到imageview時,圖像的高度較小,因此應該在圖像之間添加一些黑色空間和listview。但是當我把textview它工作正常。這裏是代碼片斷..ImageView和相對佈局中的列表視圖

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 
<RelativeLayout android:id="@+id/header" 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight"> 
<ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginTop="-10dp" 
     android:src="@drawable/bar" /> 

</RelativeLayout> 

<ListView 
android:id="@+id/list11" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:layout_marginTop="65dp" 
android:cacheColorHint="#000000" 
android:focusable="false" 
android:listSelector="@color/itemcolor1" 
android:scrollbars="vertical" 
android:scrollingCache="false" > 
</ListView> 

</RelativeLayout> 

謝謝你們,很是煩人

+1

爲什麼2個獨立的RelativeLayouts備查?你想要什麼樣的佈局? –

回答

0

試試這個...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:weightSum="10" 
android:orientation="vertical" 
> 
<ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="0dip" 
     android:layout_marginTop="-10dp" 
     android:scaleType="fitXY" 
     android:layout_weight="2" 
     android:src="@drawable/actionbar_background" 
     android:adjustViewBounds="true" 
     /> 

<ListView 
android:id="@+id/list11" 
android:layout_width="fill_parent" 
android:layout_height="0dip" 
android:layout_alignParentLeft="true" 
android:layout_below="@+id/imageView1" 
android:cacheColorHint="#000000" 
android:focusable="false" 
android:layout_weight="8" 
android:scrollbars="vertical" 
android:scrollingCache="false" > 
</ListView> 

</LinearLayout> 
0

嘗試設置規模類型的圖像視圖:

android:scaleType="fitXY" 
0

請試試這個:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 
<ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:layout_marginTop="-10dp" 
     android:scaleType="center" 
     android:src="@drawable/bar" /> 

<ListView 
android:id="@+id/list11" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:layout_below="@+id/imageView1" 
android:layout_marginTop="65dp" 
android:cacheColorHint="#000000" 
android:focusable="false" 
android:listSelector="@color/itemcolor1" 
android:scrollbars="vertical" 
android:scrollingCache="false" > 
</ListView> 

</RelativeLayout> 
1

謝謝你們的回答,幫助了很多解決它,但這些問題的答案需要一些小的調整,所以我寫這裏爲他人

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="65dp" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true" 
    android:scaleType="fitXY" 
    android:layout_weight="2" 
    android:layout_marginTop="-10dp" 
    android:src="@drawable/bar" /> 

    <ListView 
    android:id="@+id/list11" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/imageView1" 
    android:cacheColorHint="#000000" 
    android:focusable="false" 
    android:layout_weight="8" 
    android:scrollbars="vertical" 
    android:scrollingCache="false" 
    android:listSelector="@color/itemcolor1"> 
    </ListView> 

    </RelativeLayout>