GridLayout pushes its children and overflows when fill_parent is set for height

It seems that GridLayout will always push its children to a layout that matches their needs. for example, the following declaration:

<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:columnCount="3"
    android:orientation="vertical"
    android:rowCount="4"
    android:useDefaultMargins="true" >
...
    <ImageView
        android:id="@+id/main_image"
        android:layout_column="1"
        android:layout_columnSpan="2"
        android:layout_row="3"
        android:scaleType="fitStart" />
</GridLayout>

GridLayout declares fill_parent, and so I expect it to not overflow. GridLayout should accept the size of the parent, which in this case is the window (full height). However, in the hierarchy viewer, GridLayout is set to both Wrap_content for both vertical and horizontal.

Thus, an ImageView (representing a large image) or any textual representation will click to fit on its own and as such a container overflow.

, :

container grid view

image view

, , . , . useDefaultMargins="false" , gridlayout.

:

  • GridLayout.
  • GridLayout
+5
1

- : layout_weight = "1.0" . , , . XML, ImageView, TextView . layout_weight, ImageView, .

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white"
    android:orientation="vertical"
    android:keepScreenOn = "true" >

    <ImageView
        android:id="@+id/imageView_surprise"
        android:layout_width="wrap_content"
        android:layout_height="0dip"
        android:scaleType="centerInside"
        android:contentDescription="@string/accessibility_imageView_surprise"
        android:layout_weight="1.0" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="bottom" >

        <TextView
            android:id="@+id/textView_message"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="24sp"
            android:gravity="center_horizontal" />

        <Button
            android:id="@+id/button_share"
            style="@style/button_text"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

</LinearLayout>
0

All Articles