AndreaNobili AndreaNobili - 5 months ago 17
Java Question

Is it better use an horizontal LinearLayot or TableLayout?

I am absolutly new in Android development and I have the following doubt developing my first app.

I have to horizontally divide my layout in 2 section having the same size (half screen have to be occupied by the left setion and half screen by the right section).

These 2 sections have to contains some text\images.

What is the best strategy to do it? Using an horizontally

LinearLayout
or something like a
TableLayout
?

Answer

The main purpose of TableLayout is you can easily divide your layout into rows and columns.

For such a simple layout you could just use a horizontal LinearLayout that contains two layouts for your left and right content.

For example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <!-- left content -->

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <!-- right content -->

    </RelativeLayout>
</LinearLayout>