当SoftKeyboard可见时,RecyclerView隐藏工具栏和布局

时间:2015-02-15 18:22:54

标签: android toolbar android-softkeyboard android-recyclerview

我的问题与此LINK完全相同,布局中的情况相同,组件相同。 唯一的区别是工具栏,但显然我正在使用appcompat并且行为是相同的。

注意,不仅隐藏了工具栏,还隐藏了recyclerview的上半部分。就像在软键盘可见时翻译整个片段一样。

我在我的活动的main.xml中使用了这样的工具栏:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include layout="@layout/toolbar" />

    <FrameLayout
        android:id="@+id/container_root"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

Tha framelayout被替换为:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical"
    tools:ignore="MergeRootFrame" >

    <!--<include layout="@layout/toolbar" />-->

    <com.astuetz.PagerSlidingTabStrip
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/primary"
        android:textColor="#FFFFFF"
        app:pstsIndicatorColor="#FFFFFF"
        app:pstsPaddingMiddle="true"
        android:maxHeight="20dp"
        android:elevation="5dp"
    />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    </LinearLayout>

在视图寻呼机内部,我有一个带有此片段布局的标签,其中包含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:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerViewChat"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="50dip"/>


    <EditText
        android:id="@+id/txtChatLine"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/txt_hint"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_toStartOf="@+id/button1">
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_send"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

当我开始在edittext中输入文本时,整个布局都会上升,工具栏变得不可见(在屏幕外)并且recyclerview不会滚动,但它会向上移动。

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,而@drakeet解决方案对我有用: RecyclerView hides Actionbar when SoftKeyboard is opened

我在工具栏和RecyclerView之间包含一个空的ScrollView,工具栏停止隐藏。

<include android:id="@+id/app_bar" layout="@layout/toolbar"/>

<!--Empty ScrollView needed so the recyclerview doesn't hide the toolbar-->
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</ScrollView>

<view
    android:id="@+id/recycler_view"
    android:layout_below="@id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="android.support.v7.widget.RecyclerView"
    android:layout_above="@+id/message_layout"/>

答案 1 :(得分:0)

从AndroidManifest.xml中删除myObservable .compose(parent.bindToLifecycle()) .subscribe();