我试图将imageview和listview放在两个独立的相对布局中,但是当我将图像添加到imageview时,图像的高度应该更小,它会在图像和列表视图之间添加一些黑色空间。但是当我把textview它运行正常。这是代码片段..
<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>
谢谢你们,这很烦人
答案 0 :(得分: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>
答案 1 :(得分:0)
尝试设置图像视图的比例类型:
android:scaleType="fitXY"
答案 2 :(得分: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>
答案 3 :(得分: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>