You are right that RelativeLayout
is difficult to make into tables such as the one you made above. LinearLayout
is really ideal for that, which is why the TableLayout
and TableRow
view groups are subclasses of LinearLayout
. I can recommend a couple of alternatives besides RelativeLayout
that will increase layout efficiency, however.
First, you can eliminate the second vertically oriented LinearLayout
and change the layout weight of the first 4 rows of buttons from 1 to 1.25. This will reduce the number of layout passes from 8 to 4, which is the best you can do for a table.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="23" >
<!-- Insert Title/Picture in Linear Layout below -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:background="@drawable/etho_logo"
android:orientation="horizontal" >
</LinearLayout>
<!-- This is the 1st line of buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.25"
android:orientation="horizontal"
android:weightSum="3" >
<!-- 3 buttons here -->
</LinearLayout>
<!-- This is the 2nd line of buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.25"
android:orientation="horizontal"
android:weightSum="3" >
<!-- 3 buttons here -->
</LinearLayout>
<!-- This is the 3rd line of buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.25"
android:orientation="horizontal"
android:weightSum="3" >
<!-- 3 buttons here -->
</LinearLayout>
<!-- This is the 4th line of buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.25"
android:orientation="horizontal"
android:weightSum="3" >
<!-- 3 buttons here -->
</LinearLayout>
<!-- Random Button and Stop button below here -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:orientation="horizontal"
android:weightSum="3" >
<Button
android:id="@+id/bIntro"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/hello_real_select" />
<Button
android:id="@+id/bIntro"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/hello_real_select" />
</LinearLayout>
</LinearLayout>
Another option is to use a single layout that makes a "flat" grid (a ViewGroup
that manages the layout of its children into a table by itself). If you are targeting API level 14+ for your app, you can look at GridLayout
. If you are targeting an API level prior to 14, you might have to make your own. On a final note, please do not confuse GridLayout
with the GridView
view group, which is meant to be used with lists and will not accomplish what you want.