Layout_height always wraps content

This is a simple question:

I have a layout file that is presented as an element inside a ListView. I set the height of the RelativeLayout to 100dp, but it does not work, it always wraps the contents, no matter what layout I use. What can I do to set a fixed value to the height of the layout without wrapping it?

Thanks for the help.

<?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="100dp"> <!-- this attribute seems to be ignored --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true"> <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="@dimen/progressbar_small" android:layout_height="@dimen/progressbar_small" android:layout_gravity="center_vertical" /> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/loading" android:layout_gravity="center_vertical" style="@style/ListItemSubtext" /> </LinearLayout> </RelativeLayout> 
+4
source share
4 answers

I think that in the list view, all elements have the same height. In your case, you can add a progress bar as a list footer. Add a dummy tree height adjuster just before or after ListItemSubtext. Try using TableLayout instead of Relative and Linear Layout.

The dummy controller is similar to this.

 <View android:layout_width="wrap_content" android:layout_height="100dip"/> 

Please note that you do not need xmlns in each element.

+4
source

Do the following:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minHeight="100dip"> 
+6
source

Try using only 100px. It works for me.

0
source

I am making below changes to your xml ..

 <?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="100dp"> <!-- this attribute taking a fixed value as u said --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_centerHorizontal="true" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="center_vertical" android:layout_width="20dip" android:layout_height="20dip"/> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:text="@string/loading" android:layout_gravity="center_vertical" style="@style/ListItemSubtext" /> </LinearLayout> 

If this does not work for you, tell me what exactly you want to do.

0
source

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


All Articles