Android软键盘隐藏了RecyclerView

时间:2016-09-10 13:07:05

标签: android android-recyclerview chat android-softkeyboard

我尝试在底部使用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>

2 个答案:

答案 0 :(得分:1)

正确的答案是adjustResize,因此应用程序会在键盘上方调整大小。但是为了实现这一点,您需要编写其余的布局以使其可以调整大小。你不是,因为回收者的观点没有固定到位。在其上添加layout_above="@+id/chatBox"约束,使其在编辑文本上方放置,并应调整大小以适应空间。

此外,adjustPan不会隐藏键盘。如果是这样,您的代码中就会出现问题。 adjustPan可以在不调整大小的情况下滑动您的应用。如果您可以找到应用中隐藏键盘的内容,那么这可能是您想要的。

答案 1 :(得分:1)

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

android:windowSoftInputMode="adjustPan"
相关问题