软键盘覆盖 ScrollView 布局中的 editText

Fel*_*der 3 android android-layout android-edittext

我正在使用这种布局处理 Android 片段:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/very_dark_transparent_grey"
    tools:ignore="MissingPrefix">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/invite_code_input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/spacing_semi_huge"
        android:gravity="center_horizontal"
        android:orientation="vertical">

        <TextView
            fontPath="fonts/helveticaneue/Helvetica Neu Bold.ttf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/join_fragment_invite_code"
            android:textColor="@color/white"
            android:textSize="@dimen/font_larger" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingLeft="@dimen/spacing_huge"
            android:paddingRight="@dimen/spacing_huge">

            <io.brandie.brandie.custom.InviteCodeEditText
                android:id="@+id/invite_code_edit_text"
                fontPath="fonts/helveticaneue/Helvetica Neu Bold.ttf"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/spacing_smaller"
                android:cursorVisible="false"
                android:digits="1234567890"
                android:inputType="number"
                android:maxLength="6"
                android:textIsSelectable="false"
                android:textSize="32sp" />

        </LinearLayout>

        <TextView
            fontPath="fonts/helveticaneue/Helvetica Neu Bold.ttf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/spacing_large"
            android:layout_marginBottom="@dimen/spacing_large"
            android:text="@string/join_fragment_or"
            android:textColor="@color/lightGreen"
            android:textSize="@dimen/font_large"/>

    </LinearLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/invite_code_input_layout">

        <RelativeLayout
            android:id="@+id/message_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/request_to_join_text"
                fontPath="fonts/helveticaneue/Helvetica Neu Bold.ttf"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/spacing_big"
                android:gravity="center"
                android:text="@string/join_fragment_pers_mess"
                android:textColor="@color/white" />

            <EditText
                android:id="@+id/request_to_join_text_area"
                android:layout_width="280dp"
                android:layout_height="120dp"
                android:layout_below="@+id/request_to_join_text"
                android:background="@drawable/rounded_edit_text"
                android:gravity="top|start"
                android:hint="@string/join_fragment_hint"
                android:inputType="textMultiLine"
                android:lines="6"
                android:layout_centerInParent="true"
                android:overScrollMode="always"
                android:paddingLeft="@dimen/spacing_normal"
                android:paddingRight="@dimen/spacing_normal"
                android:scrollHorizontally="false"
                android:scrollbars="vertical"
                android:textSize="@dimen/font_normal" />

            <TextView
                android:id="@+id/request_to_join_send_button"
                fontPath="fonts/helveticaneue/Helvetica Neu Bold.ttf"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/request_to_join_text_area"
                android:layout_marginTop="@dimen/spacing_semi_small"
                android:gravity="center"
                android:text="@string/join_fragment_send"
                android:textColor="@drawable/primary_text_color"
                android:textSize="@dimen/font_semi_epic" />

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/pending_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:visibility="gone">

            <RelativeLayout
                android:id="@+id/checkbox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ProgressBar
                    android:id="@+id/circle_around_check"
                    style="?android:attr/progressBarStyleHorizontal"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:max="100"
                    android:progress="100"
                    android:progressDrawable="@drawable/circular_lightgreen_border"
                    android:rotation="0"
                    android:visibility="visible" />

                <ImageView
                    android:id="@+id/progress_card_check_mark"
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/douglas_273_checkmark_white"
                    android:visibility="visible" />
            </RelativeLayout>

            <TextView
                android:id="@+id/request_pending_text"
                fontPath="fonts/helveticaneue/Helvetica Neu Bold.ttf"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/checkbox"
                android:gravity="center"
                android:text="@string/join_fragment_req_pend"
                android:textColor="@color/white"
                android:textSize="@dimen/font_semi_epic" />

            <TextView
                android:id="@+id/request_pending_edit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/request_pending_text"
                android:layout_marginTop="10dp"
                android:gravity="center"
                android:text="@string/join_fragment_edit"
                android:textColor="@drawable/primary_text_color"
                android:textSize="@dimen/font_large" />

           </RelativeLayout>

       </RelativeLayout>

   </RelativeLayout>

  </ScrollView>
Run Code Online (Sandbox Code Playgroud)

问题出在 Edittext 上,当我按下它时,软键盘几乎覆盖了整个 EditText,因此无法看到您键入的内容。在清单中,我添加了以下行:

android:windowSoftInputMode="adjustPan"
Run Code Online (Sandbox Code Playgroud)

对于片段附加到的活动(我也测试了“adjustResize”,但我遇到了同样的问题)。

我还测试了在同一活动中将 editText 复制到另一个布局文件,然后键盘不会覆盖 editText 而是将整个布局向上推。如果我改为复制整个布局并将其放在另一个布局中,我会遇到覆盖editText的键盘问题。

这让我相信这种布局的某些东西是导致此问题的原因,但我无法弄清楚是什么原因导致它以及如何解决它。我该如何解决?

Thu*_*der 5

首先,将此代码添加到您的父级 ScrollView

android:isScrollContainer="true"
Run Code Online (Sandbox Code Playgroud)

并转到您的AndroidManifest.xml文件和

将此以下代码添加到您的 中activity tag android:windowSoftInputMode="adjustPan",如下所示:-

<activity
   android:name=".YourActivity"
   android:windowSoftInputMode="adjustPan"
 />
Run Code Online (Sandbox Code Playgroud)