Single row for fill_parent ListView height

There is one line in the View list that I want to be at the same height as the listView (let's say this is full screen).

The line 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 getView adapter

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

The string is displayed in the same way as with android:layout_height="wrap_content" .

A preview of the layout shows a line filling its parent, and I use inflate(R.layout.myrow, parent, false); The listView is certainly displayed in full screen mode, and the line is only as tall as the image + textView.

Am I missing something important?

+4
source share
3 answers

I had a similar problem, I think I decided to report it this way.

I have more rows in my ListView, but I want the row height to be the same in the list, which in turn will take up the rest of the layout space. My line consists of only one ImageView. I had problems with the following:

-I want smaller images to expand to take up all the space -Byr images should not exceed the line height

If I made any mistake, 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> 

Line 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 getView adapter it’s important

 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 it has. Hth

+5
source

just wondering if there is any specific reason why you want to have a ListView containing only one row? Unlike using RelativeLayout directly instead of ListView?

+3
source

I ended up with hardcoding line height. There is a problem with the relative layout after setting its minimum value, so I also replaced it with LinearLayout with centered gravity.

Please let me know if there is a better solution allowing Android to do this work and minimize hard code.

0
source

Source: https://habr.com/ru/post/1442067/


All Articles