I have a Grid with two columns, each with a label. I want the label on the 2nd column to align to the right:
<androidx.gridlayout.widget.GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
app:columnCount="2">
<TextView
android:text="Cell 0"
app:layout_column="0"
app:layout_columnWeight="1"
android:background="#FF0000" />
<TextView
android:text="Cell 1"
app:layout_column="1"
app:layout_columnWeight="1"
app:layout_gravity="right"
android:background="#0000FF"/>
</androidx.gridlayout.widget.GridLayout>
How can I make the 1st column to be equal to the 2nd column, like in the mockup below?
I tried setting android:gravity="right" but it solves half of the problem. Columns are equal in width, but the blue label fills the column:
<TextView
android:text="Cell 1"
app:layout_column="1"
app:layout_columnWeight="1"
android:gravity="right"
android:background="#0000FF"/>
The way GridLayout computes the width of a proportionally sized column is very weird. It appears it takes into account the width of the child view. The documentation does not help in describing how the layout_columnWeight works exactly.



try below code this may result what you expected