build.gradle
compile 'com.android.support:gridlayout-v7:25.3.1'
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="ir.mhdr.a084.MainActivity"> <android.support.v7.widget.GridLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Left" app:layout_column="0" app:layout_columnWeight="1" app:layout_row="0" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Center" app:layout_column="1" app:layout_columnWeight="1" app:layout_row="0" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Right" app:layout_column="2" app:layout_gravity="fill_vertical" app:layout_row="0" app:layout_rowSpan="2" app:layout_columnWeight="1"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bottom" app:layout_column="0" app:layout_columnSpan="2" app:layout_columnWeight="1" app:layout_gravity="fill_horizontal" app:layout_row="1" /> </android.support.v7.widget.GridLayout> </RelativeLayout>
References
https://github.com/mhdr/AndroidSamples/tree/master/084
https://developer.android.com/reference/android/widget/GridLayout.html
https://www.youtube.com/watch?v=4bXOr5Rk1dk
http://stackoverflow.com/questions/10016343/gridlayout-not-gridview-how-to-stretch-all-children-evenly