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