出现键盘时如何阻止EditText向上移动

出现键盘时如何阻止EditText向上移动

本文介绍了出现键盘时如何阻止EditText向上移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在底部导航活动中,我有一个带有按钮,EditText和TextView的片段.

In a Bottom Navigation Activity I've a Fragment with a button, an EditText and a TextView.

问题是,当我将EditText聚焦在键盘上时,它会向上移动,并且其中的按钮会出现错误.我该怎么解决?

The problem is that when I focus the EditText to write with the keyboard it moves up and the button bugs in it. How can I solve?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"

    <TextView
            android:layout_width="0dp"
            android:layout_height="178dp"
            android:gravity="start|top"
            android:ems="10"
            android:id="@+id/output"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent"
            android:autofillHints="" app:layout_constraintVertical_bias="0.386"
            app:layout_constraintTop_toBottomOf="@+id/button" app:layout_constraintHorizontal_bias="0.666"
            style="@style/Widget.AppCompat.TextView" android:scrollbars="vertical" android:textSize="18sp"
    />
    <EditText
            android:layout_width="0dp"
            android:layout_height="178dp"
            android:inputType="textMultiLine"
            android:gravity="start|top"
            android:ems="10"
            android:id="@+id/input"
            app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.666"
            android:autofillHints="" android:hint="@string/hint" android:layout_marginTop="16dp"
            app:layout_constraintBottom_toTopOf="@+id/button" app:layout_constraintVertical_bias="0.574"
            android:scrollbars="vertical"/>
    <Button
            android:text="@string/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/button"
            app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintHorizontal_bias="0.498" app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

推荐答案

使用此'android:windowSoftInputMode =" adjustPan"'
在AndroidMenifest.xml文件中

Use this' android:windowSoftInputMode="adjustPan" '
in AndroidMenifest.xml file

 <activity
       android:name=".ui.activity.approve_pending.ApprovalsActivity"
       android:windowSoftInputMode="adjustPan" />


您将在此处找到更多信息 https://developer.android.com/training/keyboard-input/visibility

You will find more information here https://developer.android.com/training/keyboard-input/visibility

这篇关于出现键盘时如何阻止EditText向上移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 21:41