I want to evenly spread 8 buttons using GridLayout
. I want to support the APIs lower than 21 (which is the minimum number that supports layout_columnWeight
and layout_rowWeight
in GridLayout
)
Here's my code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="tk.adamnafie.basicphrases.MainActivity"
android:background="@drawable/background">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_column="0"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:id="@+id/button1"
android:onClick="talk"
android:text="Good Morning"
android:layout_width="150dp" />
<Button
android:layout_column="1"
android:layout_row="0"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:id="@+id/button2"
android:onClick="talk"
android:text="Good Afternoon"
android:layout_width="150dp" />
<Button
android:layout_column="0"
android:layout_row="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:id="@+id/button3"
android:onClick="talk"
android:text="Good night"
android:layout_width="150dp" />
<Button
android:layout_column="1"
android:layout_row="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:id="@+id/button4"
android:onClick="talk"
android:text="How are you?"
android:layout_width="150dp" />
<Button
android:layout_column="0"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:id="@+id/button5"
android:onClick="talk"
android:layout_width="150dp"
android:text="Can you talk English?" />
<Button
android:layout_column="1"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:id="@+id/button6"
android:onClick="talk"
android:layout_width="150dp"
android:text="I am learning German" />
<Button
android:layout_column="0"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:id="@+id/button7"
android:onClick="talk"
android:layout_width="150dp"
android:text="Where do you live?" />
<Button
android:layout_column="1"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_gravity="fill"
android:id="@+id/button8"
android:onClick="talk"
android:layout_width="150dp"
android:text="I come from Egypt" />
</GridLayout>
</RelativeLayout>
I want to support Android 4.0 as minimum SDK. Is there an easy way to do so?