Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single row to fill_parent ListView height

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 ?

like image 477
A-Live Avatar asked Feb 19 '23 17:02

A-Live


1 Answers

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

like image 61
Čikić Nenad Avatar answered Feb 21 '23 07:02

Čikić Nenad