安卓软键盘遮挡了RecyclerView

6
我正在尝试使用RecyclerView和固定的底部EditText来创建评论/聊天布局。请不要使用adjustPanadjustResize,因为它们无效。adjustPan会隐藏键盘。我真的需要帮助,这让我非常沮丧。
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/appbarlayout"
        android:paddingTop="@dimen/app_bar_top_padding">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            android:id="@+id/toolbar"
            app:titleTextColor="#FFFFFF" />

    </android.support.design.widget.AppBarLayout>


    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycler_view"
        android:layout_below="@+id/appbarlayout"
        android:isScrollContainer="false"
        android:stackFromBottom="true"
        android:transcriptMode="normal"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#2b2b2b"
        android:orientation="vertical"
        android:id="@+id/chat_box"
        android:layout_alignParentBottom="true">

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="?android:attr/listDivider"/>

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp">

            <EditText
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:hint="Skriv en kommentar"
                android:background="@android:color/transparent"
                android:textColor="@color/white"
                android:textColorHint="#d4d4d4"
                android:inputType="textCapSentences|textMultiLine"
                android:layout_marginRight="40dp"/>

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_send"
                android:background="@drawable/click"
                android:layout_gravity="right|center_vertical" />

        </FrameLayout>

    </LinearLayout>


</RelativeLayout>

3个回答

2

不知道为什么,但是 Gabe Sechan 给出的解决方案对我不起作用。对我有用的是在清单文件中添加以下内容。

android:windowSoftInputMode="adjustPan"

1
我的RecyclerView随着键盘的移动而移动,这显然不是我想要的。
“adjustResize”:活动的主窗口始终被调整大小,以为软键盘腾出空间。
“adjustPan”:活动的主窗口不会被调整大小以为软键盘腾出空间。相反,窗口的内容会自动平移,以便当前焦点永远不会被键盘遮挡,用户可以始终看到他们正在输入什么。这通常比调整大小更不可取,因为用户可能需要关闭软键盘才能访问和与窗口中被遮挡的部分进行交互。
第一种方法是在清单文件中设置android:windowSoftInputMode="adjustResize",但结果并不理想。
然而,我的第二种方法android:windowSoftInputMode="adjustPan",正如@Kishan Solanki所提到的那样,确实奏效了。
我的布局是一个约束布局,包裹着一个相对布局,再包裹着我的RecyclerView。

0
正确答案是adjustResize,这样应用程序就会在键盘上方调整大小。但是为了使其正常工作,您的布局的其余部分需要编写为可调整大小。由于回收站视图没有固定位置,因此您的布局不是可调整大小的。在其上添加一个layout_above="@+id/chatBox"约束,使其布局位于编辑文本上方,它应该可以调整大小以适应空间。
另外,adjustPan不会隐藏键盘。如果它确实这样做,那么您的代码可能存在严重问题。adjustPan将您的应用程序向上滑动而不调整大小。如果您能找出在您的应用程序中隐藏键盘的原因,这可能是您想要的。

不确定为什么,但对我不起作用。布局与以下相同:<relativelayout><edittext with bottom true/><recyclerview with above edittext/></relativelayout> - Kishan Solanki

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接