I have a GridLayout
that consists of 6 children. It has a column count of 2. The left column's children have a layout_gravity
of start|end|fill_horizontal
and layout_width
of 0dp, which causes them to fill all available space.
This is great, and gives me the output shown below.
Views 4, 5, and 6 are only as big as they need to be. Very cool. I would now like to align views 4, 5, and 6 to the right hand side of the container, but this has proved challenging. Because of the way GridLayout
determines column flexibility, giving the right column's views a layout_gravity
of right
ruins the layout. Views in the first column no longer fill the remaining width in the layout. (From my understanding, this is because now both columns have children defining a horizontal gravity, so GridLayout
can no longer mark one column as flexible).
Is there a way to achieve this? I'm really not keen on nesting LinearLayout
s. Below is my desired result.
For reference, the current view hierarchy XML looks something like...
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2">
<View
android:id="@+id/view1"
android:layout_gravity="start|end|fill_horizontal" />
<View
android:id="@+id/view4" />
<View
android:id="@+id/view2"
android:layout_gravity="start|end|fill_horizontal" />
<View
android:id="@+id/view5" />
<View
android:id="@+id/view3"
android:layout_gravity="start|end|fill_horizontal" />
<View
android:id="@+id/view6" />
</GridLayout>
TextView
s doesn't seem relevant to the problem. – AnnisTableLayout
, but that's not question. I'm interested in whether or not what I want is possible with aGridLayout
. ATableLayout
will use multiple layout() passes to get the job done. AGridLayout
would be much more efficient. – Annis