软键盘覆盖ScrollView-layout

时间:2018-06-01 09:20:41

标签: 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>

问题在于Edittext,当我按下它时,软键盘几乎覆盖了整个EditText,使得无法看到你键入的内容。在清单中,我添加了一行:

android:windowSoftInputMode="adjustPan"

表示片段附加到的活动(我还测试了#34; adjustResize&#34;,但我遇到了同样的问题)。

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

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

1 个答案:

答案 0 :(得分:1)

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

android:isScrollContainer="true"

并转到您的AndroidManifest.xml文件和

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

<activity
   android:name=".YourActivity"
   android:windowSoftInputMode="adjustPan"
 />