android - 键盘打开时按钮与 EditText 重叠

标签 android android-layout android-xml android-softkeyboard android-constraintlayout

我的 Android 应用程序中有以下 ConstraintLayout:

<android.support.constraint.ConstraintLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@color/white">

      <ImageView
          android:id="@+id/image_icon"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/icon"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          />

        <TextView
          android:id="@+id/instructions"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="@dimen/spacing_large"
          android:text="@string/instruction"
          app:layout_constraintTop_toBottomOf="@id/support_ic"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          />

      <Button
        android:id="@+id/call_button"
        android:layout_marginTop="@dimen/spacing_large"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:text="@string/phone"
        android:textSize="18sp"
        android:textColor="@drawable/button"
        app:layout_constraintTop_toBottomOf="@+id/instructions"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        />


      <EditText
          android:id="@+id/message_content"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:lines="8"
          android:hint="@string/support_message_hint"
          android:textColorHint="@color/text_hint"
          android:inputType="textCapSentences|textMultiLine"
          android:background="@color/background_gray"
          android:padding="@dimen/spacing_small"
          android:textColor="@color/black"
          app:layout_constraintBottom_toTopOf="@+id/send_button"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          android:gravity="top|left"
          app:layout_constraintHorizontal_weight="1"
          app:layout_constraintVertical_weight="1"
           />

        <Button
          android:id="@+id/send_button"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:text="@string/support_send"
          android:background="@color/button_blue"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintEnd_toEndOf="parent" />

  </android.support.constraint.ConstraintLayout>

当我打开键盘时, View 会调整并且底部的两个小部件(按钮和 editText)会随着键盘移动。然而,我的问题是,每当发生这种情况时,@id/call_button 按钮都会位于 editText 之上。我不想这样。我希望 editText 在键盘打开时覆盖按钮。

在这种情况下,有没有办法让 editText 在与其他小部件重叠时优先?我尝试在我的 onCreate 方法中添加 editText.bringToFront(),但这没有做任何事情。

此外,我试图避免将底部的两个小部件(按钮和 editText)嵌套在它们自己的布局中。我希望它们都保留在同一个 ConstraintLayout 中。感谢您提前提供帮助。

keyboard open image

keyboard closed image

最佳答案

我将 android:elevation="4dp" 添加到 editText 的 xml 中,它起作用了。

关于android - 键盘打开时按钮与 EditText 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46960942/

相关文章:

java - 线程完成时更改布局

android - 自定义复选框可绘制的大小?

android - 将两个并排的 ImageView 居中

Android ViewPager 无法加载第三个 fragment

android - flutter 中的 FCM 自定义通知图标

javascript - 在 Android WebView 中显示 Javascript 小部件

Android Color - primaryColorDark 比 primaryColor 深多少?

Android 文件提供程序非法参数异常

android - 从 NDK 中的像素数组创建 Android 的可变位图

android - 使用 Proguard 混淆后出现 SuperNotCalledException