android - RecyclerView 在打开软键盘时隐藏操作栏

标签 android android-layout listview android-5.0-lollipop android-recyclerview

我有以下布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container">

    <com.example.SendMessageLayout
        android:id="@+id/chatMessageLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        />

    <View
        android:id="@+id/separator"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_above="@id/chatMessageLayout"
        android:background="@color/seperator_line_inpost"
        />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_above="@id/separator"
        >

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycleView"
            style="@style/BeepMeListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/chatMessageLayout"
            android:layout_alignParentTop="true"
            android:transcriptMode="alwaysScroll"
            />
    </android.support.v4.widget.SwipeRefreshLayout>

</RelativeLayout>

虽然 SendMessageLayout 只是一个带有 EditText 和一个 Button 的布局。 在旧的实现中,我使用普通的旧 ListView,所以当我请求焦点编辑文本时,键盘会出现, ListView 没有移动,第一个项目是可见的。 但是有了 RecyclerView,一切都被推上去,不仅最上面的项目超出了屏幕,而且整个布局都在 ActionBar 的顶部。

这是它的样子…… RecycleView Screenshot

最佳答案

只需添加一个空的 ScrollView ,已解决:RecyclerView hides Actionbar when SoftKeyboard is opened 解决办法

像这样:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    tools:context="me.drakeet.seashell.ui.social.PostActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ScrollView>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <me.drakeet.seashell.widget.MultiSwipeRefreshLayout
            android:layout_weight="1"
            android:layout_marginBottom="4dp"
            android:id="@+id/swipe_refresh_layout"
            style="@style/BbsBackground"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_reply_list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="48dp"/>

        </me.drakeet.seashell.widget.MultiSwipeRefreshLayout>

        <include
            android:layout_gravity="bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/view_reply"/>
    </LinearLayout>

</FrameLayout>

关于android - RecyclerView 在打开软键盘时隐藏操作栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27212580/

相关文章:

android - 捕获在自定义 View (布局)中选择的上下文菜单项的方法是什么?

android - coordinatorlayout 中的 Recyclerview

android - 如何在 Android 中创建可滚动的轮播页面?

android - 如何使用区域设置和配置在我的语言更改时选择不同的 Assets 文件?

android - 在 ListView 中创建简单的字母滚动?

android - 在 android 中的 ListView 内的按钮上设置 OnClick 监听器

android - 在 Android Listview 中显示流数据的最佳方式

Android:在异步任务期间处理后退按钮

java - 读取套接字输入流而没有传输结束字符?

android - 带对象的 Xamarin ListView