SoftKeyboard与EditText-ConstraintLayout重叠

时间:2019-02-13 08:12:45

标签: android android-edittext android-constraintlayout soft-keyboard

我使用ConstraintLayout创建了一个注册表单。 它包含EditText字段的垂直堆栈。 前三个EditText可以正常显示,我可以在可见SoftKeyboard的情况下键入它们。但是,对于其他EditText字段,它们完全隐藏在SoftKeyboard的后面。

以下是我面临的这个布局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:id="@+id/rootView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    android:isScrollContainer="true"
    android:verticalScrollbarPosition="left"
    android:fitsSystemWindows="false"
    tools:context="com.RegisterWithEmailActivity">

    <EditText
        android:id="@+id/edtRegFirstName"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginTop="108dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="@string/hintName"
        android:inputType="text"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintHorizontal_bias="0.504"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/edtRegUserName"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="Username"
        android:inputType="text"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintHorizontal_bias="0.504"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edtRegFirstName" />

    <EditText
        android:id="@+id/edtRegPassword"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="@string/hintPassword"
        android:inputType="textPassword"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edtRegUserName" />

    <EditText
        android:id="@+id/edtStreetAddress1"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="@string/hintStreetAdd1"
        android:inputType="text"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintHorizontal_bias="0.504"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edtRegPassword" />

    <EditText
        android:id="@+id/edtStreetAddress2"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="@string/hintStreetAdd2"
        android:inputType="text"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintHorizontal_bias="0.504"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edtStreetAddress1" />

    <EditText
        android:id="@+id/edtCity"
        android:layout_width="109dp"
        android:layout_height="36dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="@string/hintCity"
        android:inputType="text"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintHorizontal_bias="0.247"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edtStreetAddress2" />

    <EditText
        android:id="@+id/edtState"
        android:layout_width="113dp"
        android:layout_height="36dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="@string/hintState"
        android:inputType="text"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.116"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toEndOf="@+id/edtCity"
        app:layout_constraintTop_toBottomOf="@+id/edtStreetAddress2" />

    <EditText
        android:id="@+id/edtZipCode"
        android:layout_width="110dp"
        android:layout_height="36dp"
        android:layout_marginEnd="188dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="@string/hintZipCode"
        android:inputType="text"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edtCity" />

    <EditText
        android:id="@+id/edtGender"
        android:layout_width="112dp"
        android:layout_height="36dp"
        android:layout_marginEnd="60dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="@string/hintGender"
        android:inputType="text"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.875"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintStart_toEndOf="@+id/edtZipCode"
        app:layout_constraintTop_toBottomOf="@+id/edtState" />

    <EditText
        android:id="@+id/edtRegEmailAddress"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/shape_edittext"
        android:ems="10"
        android:hint="Email Address"
        android:inputType="text"
        android:textAlignment="center"
        android:textColor="@color/textColor"
        android:textColorHint="@color/textColor"
        android:textSize="20sp"
        app:layout_constraintHorizontal_bias="0.504"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edtGender" />

    <Button
        android:id="@+id/btnRegisterWithEmail"
        android:layout_width="200dp"
        android:layout_height="50dp"
        android:layout_marginTop="12dp"
        android:backgroundTint="@color/colorLoginButton"
        android:elevation="@android:dimen/app_icon_size"
        android:gravity="center"
        android:padding="10dp"
        android:text="REGISTER"
        android:textColor="@color/white"
        android:textSize="20sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edtRegEmailAddress" />

</android.support.constraint.ConstraintLayout>

这是AndroidManifest.xml代码段,其中对SoftKeyboard进行了一些调整。

<activity
            android:name=".RegisterWithEmailActivity"
            android:isScrollContainer="false"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.AppCompat.NoActionBar"
            android:windowSoftInputMode="adjustResize|adjustPan"></activity>

1 个答案:

答案 0 :(得分:0)

  

尝试仅使用一个子布局的Scrollview。然后将编辑文本的和按钮放在该子布局下。