【问题标题】:Soft keyboard covers editText in ScrollView-layout软键盘覆盖ScrollView-layout中的editText
【发布时间】:2018-06-01 09:20:41
【问题描述】:

我正在开发一个具有这种布局的 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"

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

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

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

【问题讨论】:

  • 添加 android:isScrollContainer="true"
  • 我试过了,没区别。

标签: android android-layout android-edittext


【解决方案1】:

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

android:isScrollContainer="true"

然后转到您的AndroidManifest.xml 文件和

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

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

【讨论】:

  • 悲哀地不起作用,我添加了你说的两个东西但没有区别,仍然是同一个问题。
  • 使用 代替 ScrollView ,然后还使用上述答案中的代码添加
  • 等等,“父 android.support.v4.widget.NestedScrollView”是什么意思?我只有一个?您是指 NestedScrollView 的父级吗?
  • no no 代替你的 ScrollView 只是尝试使用 android.support.v4.widget.NestedScrollView
  • 试一试,让我进一步了解。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多