Эмулятор Android не прокручивается вниз - PullRequest
16 голосов
/ 28 апреля 2011

Я создаю макет следующим образом, и когда я эмулирую его в AVD.Он не прокручивается вниз, чтобы увидеть содержание ниже сгиба.

<?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

1 Ответ

19 голосов
/ 28 апреля 2011

Вы должны обернуть свой макет / часть, которую вы хотите прокрутить в ScrollView.

, например, вы можете переписать свой макет как:

<?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>

, чтобы ваш корневой тег былScrollView, и вы просто вставляете свой текущий макет внутрь.вам просто нужно удалить объявление пространства имен из LinearLayout и объявить его в ScrollView.

Документы ScrollView API могут быть полезны и, конечно, «Полезные приемы ScrollView's Romain Guy» .

...