Андроид Как сделать представление ScrollView автоматически прокрутите вниз, когда нажать на полей EditText?


Я покажу вам нормальный вид макета ниже:

Изображение 1

Когда я нажал на email editText softkeyboard был всплывающим, editText является обложкой softkeyboard, это то, что показано на рисунке ниже:

Изображение 2

Итак, я хотел щелкнуть editText, и scrollView автоматически прокручивается вниз, а не закрывается softkeyboard, которые показывают, как показано на рисунке ниже:

Изображение 3

Милаут.XML-код ниже:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_account_light_brown"
android:clickable="true">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id="@+id/scroll"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginBottom="0dp"
    app:layout_constraintBottom_toTopOf="@+id/btn_login">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/constraintLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintVertical_bias="1.0">


        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            android:scaleType="fitXY"
            app:srcCompat="@drawable/bg_carousel_01" />

        <EditText
            android:id="@+id/i_email"
            android:layout_width="320dp"
            android:layout_height="49dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/rounded_shape_input"
            android:ems="10"
            android:hint="Email"
            android:inputType="textEmailAddress"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.493"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/imageView" />


        <TextView
            android:id="@+id/textViewSignUp"
            android:layout_width="284dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="300dp"
            android:fontFamily="@font/lato_bold"
            android:gravity="center"
            android:text="LOGIN"
            android:textColor="@color/white"
            android:textSize="70sp"
            android:textStyle="bold|bold"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/imageView" />

        <EditText
            android:id="@+id/i_password"
            android:layout_width="320dp"
            android:layout_height="49dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:background="@drawable/rounded_shape_input"
            android:ems="10"
            android:hint="Password"
            android:inputType="textPassword"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.493"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/i_email"
            app:layout_constraintVertical_bias="0.52" />

    </android.support.constraint.ConstraintLayout>
</ScrollView>

<Button
    android:id="@+id/btn_login"
    style="?android:attr/borderlessButtonStyle"
    android:layout_width="320dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:background="@drawable/rounded_shape2"
    android:clickable="true"
    android:text="Login"
    android:textColor="#FFFFFF"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.973" />

</android.support.constraint.ConstraintLayout>
2 2

2 ответа:

Попробуйте это использование сделать ваш ScrollView android:fillViewport="true"

android:fillViewport="true"

Определяет, должен ли scrollview растягивать свое содержимое, чтобы заполнить видовой экран.

И в файле манифеста добавьте android:windowSoftInputMode="adjustResize" в вашей активности входа

android:windowSoftInputMode="adjustResize"

Главное окно действия всегда изменяется, чтобы освободить место для мягкой клавиатуры на экране

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

Добавьте в свой Scrollview :

android:fillViewport="true"

И добавьте в свой файл Manifest:

android:windowSoftInputMode="adjustResize"