Android Emulator doesn't Scroll down

Harsha M V picture Harsha M V · Apr 28, 2011 · Viewed 9.7k times · Source

I am creating a layout as follows and when I emulate it in the AVD. It doesn't Scroll down to see the conten below the fold.

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

    <TextView android:text="@string/UserFormWelcome"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:textSize="20px" android:gravity="center" />

    <TextView android:text="@string/name" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:textStyle="bold"
        android:paddingTop="20px" android:paddingLeft="10px" />


    <TableLayout android:layout_height="wrap_content"
        android:layout_width="wrap_content">

        <TableRow android:layout_height="wrap_content"
            android:layout_width="match_parent" android:paddingTop="20px">

            <TextView android:text="@string/firstname"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:width="100px" android:paddingLeft="10px" />

            <EditText android:id="@+id/LastName" android:width="200px"
                android:layout_width="fill_parent" android:layout_height="wrap_content" />

        </TableRow>

        <TableRow android:layout_height="wrap_content"
            android:layout_width="match_parent">

            <TextView android:text="@string/lastname"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:paddingLeft="10px" />

            <EditText android:id="@+id/LastName" android:width="200px"
                android:layout_width="fill_parent" android:layout_height="wrap_content" />

        </TableRow>

    </TableLayout>


    <TextView android:text="@string/dob" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:textStyle="bold"
        android:paddingTop="20px" android:paddingLeft="10px" />

    <TableLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:stretchColumns="3"
        android:paddingTop="20px" android:paddingLeft="10px">
        <TableRow>
            <TextView android:text="@string/date" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_column="0" />

            <TextView android:text="@string/month" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_column="1" />

            <TextView android:text="@string/year" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_column="2" />
        </TableRow>
        <TableRow>
            <Spinner android:id="@+id/spinnerDate" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_column="0" />

            <Spinner android:id="@+id/spinnerMonth" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_column="1" />

            <Spinner android:id="@+id/spinnerYear" android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:layout_column="2" />
        </TableRow>


    </TableLayout>

    <LinearLayout android:id="@+id/linearLayout1"
        android:orientation="vertical" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:paddingLeft="10px">

        <TextView android:text="@string/sex" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:textStyle="bold"
            android:paddingTop="20px" />

        <RadioGroup android:id="@+id/radioGroup1"
            android:orientation="horizontal" android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <RadioButton android:text="Male" android:id="@+id/rdbMale"
                android:layout_height="wrap_content" android:layout_width="wrap_content"
                android:paddingRight="20px" android:checked="true" />
            <RadioButton android:text="Female" android:id="@+id/rdbFemale"
                android:layout_height="wrap_content" android:layout_width="wrap_content" />
        </RadioGroup>

    </LinearLayout>


    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:paddingLeft="10px">

        <TextView android:text="@string/city" android:id="@+id/textView3"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:textStyle="bold" android:paddingTop="20px"
            android:paddingBottom="10px" />

        <Spinner android:id="@+id/citySpiner" android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </Spinner>
    </LinearLayout>

</LinearLayout>

enter image description here

Answer

rekaszeru picture rekaszeru · Apr 28, 2011

You should wrap your layout / the part you want to scoll into a ScrollView.

e.g. you can rewrite your layout as:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout android:orientation="vertical"
        android:layout_height="wrap_content" android:layout_width="wrap_content">
        <TextView [...]
        [...] 
    </LinearLayout>
</ScrollView>

so your root tag will be a ScrollView, and you just paste your current layout inside.
you just need to remove the namespace declaration from your LinearLayout, and declare it in the ScrollView.

The ScrollView API Docs might be helpful, and of course, Romain Guy's "ScrollView's Handy tricks".