1

inside ListView item what I'm trying to do is to place an ImageView over a TextView while the TextView must fill it's parent, here's what i did:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">    

    <TextView android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:background="#FFFF00" />

    <ImageView android:id="@+id/icon"
        android:layout_width="50dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:background="#550000FF" />    
</RelativeLayout>

notes:

  • tried to add {android:layout_alignParentBottom="true"} to TextView - nothing changed
  • tried to use "fill_parent" instead of "match_parent" - nothing changed
  • tried to add "android:singleLine="false"" - nothing changed
  • ImageView height must be fixed, but i can't do then for TextView.
  • there is no problem when the TextView contains enough text to make it taller than image

here is a screenshot: notice that the TextView is acting like it's given "wrap_content" while it should be filling all the white space.

so what am I missing here?

thanks!

2 Answers2

0

Set the TextView height same as ImageView, since your using Relative Layout for the ListView item layout, the item height will be the maximum height of its inner child.

Change the Textview as

<TextView android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentTop="true"
    android:background="#FFFF00" />

If , the ImageView height is not fixed, then you can set the TextView height from your adapter getView method

  textview.setHeight(parent.getMeasuredHeight());

Also , setting android:layout_height="match_parent" for a ListView item parent Layout doesn't make any sense, change it to wrap_content

Libin
  • 16,967
  • 7
  • 61
  • 83
  • thanks for responding, can't fix textView height, maybe i have to do it programmatically, but how to predict textView height in getView method while setting text to it. – Alaa Khaldi May 16 '14 at 21:10
0

Change parent layout height to wrap_content it will solve your issue

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<TextView android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:background="#FFFF00" />

<ImageView android:id="@+id/icon"
    android:layout_width="50dp"
    android:layout_height="100dp"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:background="#550000FF" />
</RelativeLayout>

OR You can set minHeight=100 to TextView. This will take minimum height 100dp same as ImageView and increase its height after minimum height.

<TextView android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minHeight="100dp"
    android:layout_alignParentTop="true"
    android:background="#FFFF00" />
Sumit Jain
  • 1,100
  • 1
  • 14
  • 27