【问题标题】:RecyclerView hides Toolbar and layout when SoftKeyboard is visibleRecyclerView 在 SoftKeyboard 可见时隐藏 Toolbar 和布局
【发布时间】:2016-07-26 09:12:10
【问题描述】:

我有一个与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>

框架布局被替换为:

<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不滚动,但它向上移动。

【问题讨论】:

    标签: android toolbar android-softkeyboard android-recyclerview


    【解决方案1】:

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

    我在 Toolbar 和 RecyclerView 之间添加了一个空的 ScrollView,并且 Toolbar 停止隐藏。

    <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"/>
    

    【讨论】:

      【解决方案2】:

      从您的 AndroidManifest.xml 中删除 android:windowSoftInputMode="adjustPan"

      【讨论】:

      • 移除adjustPan等于设置adjustUnspecified,如果有可滚动元素,默认为adjustResize。如果这解决了你的问题,我认为你应该明确地写 android:windowSoftInputMode="adjustResize" 让你的代码读者明白你真的想要这个值。
      猜你喜欢
      • 2022-01-09
      • 2011-05-24
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多