5

I created a vertical linear layout and placed many items in it, and only part of them can be displayed on the screen. I can see the first several items of the layout but can't see the last several items of the layout. How can I make the linear layout scrollable so the user can scroll the screen to see the last several items of the linear layout? following is the content of the layout xml file:

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

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

        <TextView
            android:id="@+id/textView_gridw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="Grid Width"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_gridw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView_gridh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="Height"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_gridh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

        <TextView
            android:id="@+id/textView_gridbt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="Border thickness"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_gridborderthickness"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

        </LinearLayout>

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

        <TextView
            android:id="@+id/textView_bgw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="BgImg Width"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_bgw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:focusable="false"
            android:inputType="number" />

        <TextView
            android:id="@+id/textView_bgh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="Height"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_bgh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:focusable="false"
            android:inputType="number" />

        <TextView
            android:id="@+id/textView_mtgw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="MTG Width"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_mtgw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

        <TextView
            android:id="@+id/textView_mtgh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:text="Height"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_mtgh"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

    </LinearLayout>

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

        <TextView
            android:id="@+id/textView_margin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Margin(left, top, right, bottom):"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>


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

        <EditText
            android:id="@+id/editText_margin_l"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText_margin_t"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText_margin_r"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

        <EditText
            android:id="@+id/editText_margin_b"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

    </LinearLayout>

    <TextView
        android:id="@+id/textView_pathname_bg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Background image file path name:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText_pathname_bg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

    <TextView
        android:id="@+id/textView_pathname_thumbdir"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Thumbnail images directory path name:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText_pathname_thumbdir"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

    <TextView
        android:id="@+id/textView_pathname_treasure"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Treasure image file path name:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText_pathname_treasure"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

    <TextView
        android:id="@+id/textView_pathname_signature"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Signature image file path name:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText_pathname_signature"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

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

        <Button
            android:id="@+id/button_reset"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="reset"
            android:text="Reset" />
        <Button
            android:id="@+id/button_apply"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="apply"
            android:text="Apply" />
    </LinearLayout>

</LinearLayout>
Jack
  • 125
  • 1
  • 1
  • 8
  • 1
    Possible duplicate of [How do you make a LinearLayout scrollable?](http://stackoverflow.com/questions/4055537/how-do-you-make-a-linearlayout-scrollable) – Flow Aug 27 '16 at 10:02

2 Answers2

18

You should wrap your LinearLayout in a ScrollView:

Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a vertical orientation, presenting a vertical array of top-level items that the user can scroll through.

Jason Sankey
  • 2,328
  • 1
  • 15
  • 12
8

You can use ScrollView, as follows:

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

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

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

            <TextView
                android:id="@+id/textView_gridw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:text="Grid Width"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/editText_gridw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" >

                <requestFocus />
            </EditText>

            <TextView
                android:id="@+id/textView_gridh"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:text="Height"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/editText_gridh"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />

            <TextView
                android:id="@+id/textView_gridbt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:text="Border thickness"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/editText_gridborderthickness"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView_bgw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:text="BgImg Width"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/editText_bgw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:focusable="false"
                android:inputType="number" />

            <TextView
                android:id="@+id/textView_bgh"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:text="Height"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/editText_bgh"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:focusable="false"
                android:inputType="number" />

            <TextView
                android:id="@+id/textView_mtgw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:text="MTG Width"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/editText_mtgw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />

            <TextView
                android:id="@+id/textView_mtgh"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:text="Height"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <EditText
                android:id="@+id/editText_mtgh"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />
        </LinearLayout>

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

            <TextView
                android:id="@+id/textView_margin"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Margin(left, top, right, bottom):"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </LinearLayout>

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

            <EditText
                android:id="@+id/editText_margin_l"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText_margin_t"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText_margin_r"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />

            <EditText
                android:id="@+id/editText_margin_b"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:inputType="number" />
        </LinearLayout>

        <TextView
            android:id="@+id/textView_pathname_bg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Background image file path name:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_pathname_bg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

        <TextView
            android:id="@+id/textView_pathname_thumbdir"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Thumbnail images directory path name:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_pathname_thumbdir"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

        <TextView
            android:id="@+id/textView_pathname_treasure"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Treasure image file path name:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_pathname_treasure"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

        <TextView
            android:id="@+id/textView_pathname_signature"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Signature image file path name:"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/editText_pathname_signature"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" />

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

            <Button
                android:id="@+id/button_reset"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="reset"
                android:text="Reset" />

            <Button
                android:id="@+id/button_apply"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="apply"
                android:text="Apply" />
        </LinearLayout>
    </LinearLayout>
</ScrollView>

Jack
  • 131,802
  • 30
  • 241
  • 343
Joe
  • 141
  • 2
  • ScrollView works fine and my problem has been solved. Thank you all. – Jack Feb 25 '13 at 03:21
  • to Jules Mazur, I tried, but failed to delete this question. It said "Sorry, this question has answers and can't be deleted..." – Jack Feb 26 '13 at 02:54