0

I'm using support v7 GridLayout but as many others noted, it does not measure its children width correctly.

In this question, there's a workaround but the workaround works randomly for me, for some values it works, and for some children values it doesn't.

The proposed workaround:

 android:layout_width="0dp"
 app:layout_gravity="fill_horizontal"

I set child values during runtime so my guess is only toward measuring children width.

enter image description here

Community
  • 1
  • 1
Mohsen Afshin
  • 13,273
  • 10
  • 65
  • 90

2 Answers2

0

I solved using the workaround you mentioned, proposed here: Android GridLayout not clipping text to column width and here Daniel Lew's Coding Thoughts GridLayout Child View Clipping Issues works:

 android:layout_width="0dp"
 app:layout_gravity="fill_horizontal"

In my case it worked properly even when setting the child values programmatically when I applied to all children in the last column, like in the following example:

<android.support.v7.widget.GridLayout
    xmlns:grid="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/GridView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    grid:columnCount="2"
    grid:rowCount="2"
    grid:alignmentMode="alignBounds">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="Label1"
        android:id="@+id/textViewLabel1"
        grid:layout_row="0"
        grid:layout_column="0" />

    <TextView
        android:layout_width="0dp"
        grid:layout_gravity='fill_horizontal'
        android:layout_height="wrap_content"
        android:text="Value1"
        android:id="@+id/textViewValue1"
        grid:layout_row="0"
        grid:layout_column="1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="Label2"
        android:id="@+id/textViewLabel2"
        grid:layout_row="1"
        grid:layout_column="0" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        grid:layout_gravity='fill_horizontal'
        android:text="Value2"
        android:id="@+id/textViewValue2"
        grid:layout_row="1"
        grid:layout_column="1" />
</android.support.v7.widget.GridLayout>
Community
  • 1
  • 1
Dario Ceccoli
  • 304
  • 1
  • 7
0
    android:layout_width="wrap_content"
    android:layout_gravity="fill_horizontal"
Steph
  • 117
  • 4