Why does gridlayout take up only a vertical bar, although layout_height = match_parent, and parent scrollview2 occupy most of the screen?

<GridLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:columnCount="3" android:addStatesFromChildren="false" android:layout_margin="20dp" android:layout_alignParentBottom="true" android:layout_alignParentEnd="false"> <Button android:text="Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button7" /> <Button android:text="Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button6" android:elevation="1dp" /> <Button android:text="Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button4" android:onClick="gonext" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_below="@+id/textView3" android:elevation="0dp" /> </GridLayout> <TextView android:text="TextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="19dp" android:layout_marginStart="19dp" android:layout_marginTop="39dp" android:id="@+id/textView2" /> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:animationCache="true" android:fadeScrollbars="true" android:id="@+id/scrollview2" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:clipToPadding="false" android:layout_marginBottom="80dp"> <GridLayout android:layout_width="match_parent" android:layout_height="match_parent"> </GridLayout> </ScrollView> 

enter image description here enter image description here

    1 answer 1

    GridLayout ignores the android:layout_height="match_parent" due to the fact that it is nested in a ScrollView (similarly, the GridLayout nested in HorizontalScrollView will ignore the android:layout_width="match_parent" parameter android:layout_width="match_parent" ). This is normal.

    The actual height of a GridLayout determined by the size of its children, and, generally speaking, it can be greater than the height of its parent element (which is why this attribute is ignored).