Search code examples
androidxmlandroid-layoutandroid-tablelayout

Creating a two column Activity with horizontal and vertical scrolling


I'm trying to make a two column <TableLayout> in Android with vertical and horizontal scrolling.

Like this:

split screen scrolling

This is my code:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:weightSum="1.0" >

       <LinearLayout
           android:layout_width="match_parent"
           android:layout_height=".90"
           android:layout_gravity="left"
           android:layout_weight=".35" >

            <TextView
                android:id="@+id/TextView04"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#b0b0b0"
                android:text="column 1"
                android:textColor="#000000" />

        </LinearLayout> 

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_gravity="right"
            android:layout_weight=".65" > 

            <TextView
                android:id="@+id/TextView03"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#a09f9f"
                android:text="column 2"
                android:textColor="#000000" />
        </LinearLayout>
    </TableRow>

</TableLayout>

Maybe someone can help my to write all code?


Solution

  • Android -- How to allow horizontal and vertical scrolling

    So you need 4 scrollviews. 2 of horizontal and 2 of vertical.

    <LinearLayout>
    <ScrollView>
    <HorizontalScrollView >
    Column1
    </ScrollView>
    </HorizontalScrollView >
    <ScrollView>
    <HorizontalScrollView >
    Column2
    </ScrollView>
    </HorizontalScrollView >
    </LinearLayout>
    

    and the linearlayout has to be horizontal.