4

There's one row in the listView which I want to be with the same height as the listView (let's say that is full-screen).

The row layout looks like

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/error" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="14dp"
        android:minHeight="30dip"
        android:textAppearance="?android:attr/textAppearanceMedium"/>
</RelativeLayout>

And the adapter's getView is

@Override
public View getView(int position, View convertView, ViewGroup parent) {
   View row = inflater.inflate(R.layout.myrow, parent, false);
   return row;
}

Bu the row is displayed the same as it would be with android:layout_height="wrap_content".

Layout preview shows the row filling it's parent and I'm using inflate(R.layout.myrow, parent, false);, the listView is certainly displayed full-screen and the row is only as tall as the image + textView.

Am i missing something important ?

A-Live
  • 8,904
  • 2
  • 39
  • 74
  • you dont need "android:orientation="vertical"" for RelativeLayout it's rather for LinearLayouts. User "match_parent" instead of "fill_parent" and try to set some background for your root RelativeLayout in myrow.xml maybe the row has full-screen width and the problem is in placeing Image and TextView inside the listview layout ? – fgeorgiew Oct 25 '12 at 14:28
  • @fgeorgiew I know, it's left from the LinearLayout and I believe does no harm being ignored. – A-Live Oct 25 '12 at 14:29

3 Answers3

5

I had similar problem I think I have solved so reporting here.

I have more rows in my ListView, but I want that the row height be the same of the listview, which in turn shall occupy all the remaining space of the layout. My row is made of just one ImageView. I had problems with the following:

-I want that smaller images expand to occupy all the space -Bigger images shall not exapnd more than a row height

If I have made any error please leave a note here.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.9"
    android:gravity="center"
    android:orientation="vertical">
    <ListView 
        android:id="@id/lay_main_firma_objekti"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center">
    </ListView>      
</LinearLayout>   

Row layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:gravity="center">       
  <TextView
      android:id="@+id/xx"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>  
    <ImageView              
        android:id="@id/imageView_obj"
        android:contentDescription="@string/objektDesc"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignLeft="@id/xx"
        android:layout_alignTop="@id/xx"
        android:layout_alignRight="@id/xx"
        android:layout_alignBottom="@id/xx"
        android:scaleType="fitXY"
        android:src="@drawable/custom_prazno" />                    
</RelativeLayout>

Then in the Adapter getView it is important to

convertView.setMinimumHeight(parent.getMeasuredHeight());
ImageView slika=(ImageView)v.findViewById(R.id.imageView_obj);    
slika.setMinimumHeight(parent.getMeasuredHeight());
TextView xx=(TextView)v.findViewById(R.id.xx);
xx.setHeight(parent.getMeasuredHeight());

I think that is. hth

Čikić Nenad
  • 392
  • 5
  • 13
  • 3
    Thanks, `getMeasuredHeight` is a nice way to minimize hardcode although I'm not sure that `getView` is called for displayed rows during listView resizing. – A-Live Apr 14 '13 at 17:37
3

just wondering if there's a particular reason why you want to have a ListView containing only one row? As opposed to just using the RelativeLayout directly instead of ListView?

danwilkie
  • 794
  • 6
  • 10
  • Yes theres a strong reason, the listView is used to show the tabled content but sometimes I need to show the error message, and I decided to use a special row for this purpose. It fits the listView pull-to-refresh function very nicely and I don't want to link the listView datasource to any other view other than the listView, it makes things too complicated. – A-Live Oct 25 '12 at 14:16
0

I've ended up with hardcoding the row height. There is a problem with relative layout after setting it's minimumHeight so I've also replaced it with the LinearLayout with centered gravity.

Please let me know if there's a better solution letting Android to do it's job and minimizing hardcode.

A-Live
  • 8,904
  • 2
  • 39
  • 74