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

Ale*_*xis 15 android android-keypad android-layout android-scrollview

我有一些视图(名称,电子邮件,密码,注册按钮):

<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>
Run Code Online (Sandbox Code Playgroud)

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

Ale*_*s G 42

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

<activity android:name="..."
          ...
          android:windowSoftInputMode="adjustResize">
    ...
/>
Run Code Online (Sandbox Code Playgroud)


swi*_*Boy 7

我已经创建了简单的xml文件,希望这是你正在寻找的.

第1步.你可以在键盘出现时滚动.

第2步.当你点击Text-Field时,它会出现在Focus /上面的键盘上.

<ScrollView android:id="@+id/ScrollView01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true" 
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:weightSum="1.0" 
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true" 
    android:id="@+id/l_layout">
    <EditText 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:id="@+id/editText1" 
        android:layout_marginTop="100dp">
        <requestFocus></requestFocus>
    </EditText>
    <EditText 
        android:layout_height="wrap_content" 
        android:layout_width="match_parent" 
        android:id="@+id/editText2" 
        android:layout_marginTop="100dp">
        </EditText>
    </LinearLayout> 
</ScrollView>
Run Code Online (Sandbox Code Playgroud)