我使用ConstraintLayout创建了一个注册表单。它包含EditText字段的垂直堆栈。前三个EditTexts显示正常,我可以在SoftKeyboard可见时键入它们。但是,对于其他EditText字段,它们完全隐藏在SoftKeyboard后面。
以下是我的Layout 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>
尝试仅使用一个子布局的Scrollview。然后将编辑文本和按钮放在该子布局下。