繁体   English   中英

相对布局中的ImageView和ListView

[英]ImageView and listview in relative layout

我试图将imageview和listview放在两个单独的相对布局中,但是当我将图像添加到imageview时,图像的高度小于应有的高度,它在image和listview之间添加了一些黑色空间。 但是当我放置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>

谢谢大家,这很烦人

谢谢大家的回答,帮助了很多人解决了这些问题,但是这些答案需要细微的调整,所以我在这里写以供将来参考

<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>

尝试设置图像视图的比例类型:

android:scaleType="fitXY"

请尝试以下操作:

<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>

尝试这个...

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM