LinearLayout minHeight does not work with weigth = "1"

I tried all day to get the minHeight attribute.

I want a linearMe layout:

  • Stretch from the bottom of the screen to the bottom of the list when the ListView has just a few items.
  • I need to be able to fill out a linearMe layout with an image, for example.

As the ListView linearMe , I want the linearMe layout:

  • Have a fixed height (at the bottom of the screen) and ListView to allow scrolling.

My problem is that the linearMe layout linearMe smaller and smaller because there are more elements in the ListView element. And when there is enough element in the listView element to fill the screen, the linearMe layout simply disappeared. It seems that minHeight useless in this case.

  <LinearLayout android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" > <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:id="@+id/linearMe" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#FF0000" android:minHeight="200dp" /> </LinearLayout> 

enter image description hereenter image description here

I hope you can help me! :)

+8
java android xml layout
source share
2 answers

Add android:layout_weight="1" to the ListView. Change them as (list and linearMe) android:layout_height to "match_parent" Remove minHeight.

Thus, each view will occupy half the screen.

0
source share

You might want to try positioning the layout using "View" instead of "LinearLayout". ViewGroup classes sometimes handle layouts in a slightly different way.

0
source share

All Articles