出现键盘时如何使android视图可滚动?

问题描述:

我有一些字段(姓名、电子邮件、密码、注册按钮)的视图:

I have a view with some fields (name, email, password, register button) :

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

    <ViewFlipper
        android:id="@+id/viewflipper"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        //Layouts

    </ViewFlipper>

</ScrollView>

当我聚焦编辑文本字段时,键盘出现并覆盖视图上的较低字段.所以当键盘存在时我看不到它们.我想知道如何使视图可滚动,以便我可以看到较低的字段.此外,如何使视图自动滚动以使聚焦的字段可见.

When I focus an edittext field, the keyboard appears and is overlaying the lower fields on the view. So I can't see them when the keyboard is present. I would like to know how to make the view scrollable so that I can see the lower fields. And additionally, how to make the view scroll automatically to make the focused field visible.

您需要在 AndroidManifest.xml 文件中为您的活动包含 android:windowSoftInputMode="adjustResize" 属性 - 然后 Android 应该自动为您调整大小:

You need to include android:windowSoftInputMode="adjustResize" attribute for your activity in the AndroidManifest.xml file - and then Android should do the resizing for you automatically:

<activity android:name="..."
          ...
          android:windowSoftInputMode="adjustResize">
    ...
/>