Подтвердить что ты не робот

Как сделать вид андроида прокручиваемым при появлении клавиатуры?

У меня есть представление с некоторыми полями (имя, адрес электронной почты, пароль, кнопка регистрации):

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

Когда я фокусирую поле edittext, появляется клавиатура и накладывает нижние поля на представление. Поэтому я не вижу их, когда клавиатура присутствует. Я хотел бы знать, как сделать просмотр прокручиваемым, чтобы я мог видеть нижние поля. Кроме того, как сделать просмотр прокрутки автоматически, чтобы сделать сфокусированное поле видимым.

4b9b3361

Ответ 1

Вам нужно включить атрибут android:windowSoftInputMode="adjustResize" для вашей активности в файл AndroidManifest.xml, а затем Android должен автоматически изменить размер:

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

Ответ 2

Я создал простой XML файл, надеюсь, это то, что вы ищете.

шаг 1. вы можете прокручивать, когда появится клавиатура.

шаг 2. когда вы нажмете на текстовое поле, он появится на клавиатуре Focus/above.

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

Ответ 3

Вы пробовали это:

<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" >
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/scroll_container">
        //Layouts
    </ScrollView>


</ViewFlipper>

Ответ 4

В моем случае решение @Aleks G не работало. поэтому я решил проблему с помощью

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/registration_scroll_view"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/btn_register_submit"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

       <!--This comment will be replaced 
           by your focusable views-->

    </LinearLayout>
</ScrollView>

<Button
    android:id="@+id/btn_register_submit"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/form_action_button_green"
    android:gravity="center"
    android:text="@string/submit"
    />

</RelativeLayout>