键盘弹出时包含在CoordinatorLayout中的RecyclerView未调整大小

3

活动布局XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:scaleType="centerCrop"
                    android:src="@drawable/hospital_logo" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:orientation="vertical"
                    android:padding="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="******* ************* ********** ************"
                        android:textSize="18sp"
                        android:textColor="@android:color/black"
                        android:textStyle="bold"/>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="***************************"
                        android:textSize="18sp"
                        android:textColor="@android:color/black"
                        android:textStyle="bold"/>

                </LinearLayout>

            </FrameLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

我在这里使用 CoordinatorLayoutCollapsingToolbarBarViewPager 相结合。

我已经添加了两个片段到 ViewPager 中,使用以下布局 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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />

</LinearLayout>

RecyclerView的单元格包含EditText。当我选择EditText时,软键盘会弹出,但EditText会隐藏在键盘后面。

我已经向活动添加了以下标志:

android:windowSoftInputMode="adjustResize"

我正在使用23.1.1版本的appcompat,其中包含RecyclerView。
当我将CoordinatorLayout替换为LinearLayout时,RecyclerView会被调整大小以正确显示最后一个元素。因此,我认为这是与Coordinator layout有关的问题。
我查看了以下问题:https://code.google.com/p/android/issues/detail?id=176406https://code.google.com/p/android/issues/detail?id=176187,但与此错误无关。如果可以解决此问题,请告诉我如何应用。
等待回复。谢谢。 如果需要更多细节,请告诉我。

我努力修复了它。最后我为此创建了一个 Android 问题。我分享了我的样本项目以说明问题。请检查以下链接获取问题状态:https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=&id=199043 - undefined
@streamride 不,我不能修复它。我改变了设计来解决这个问题。 - undefined
2个回答

2

我曾经遇到过类似的问题,通过使用 android:windowSoftInputMode="adjustPan" 解决了它。


0
我遇到了一个类似的问题,与coordinatorLayout有关。然而,将fitsSystemWindows设置为false解决了这个问题。看起来,主要的问题是coordinatorLayout。我通过将整个布局,包括AppBarLayout,封装在一个constraintLayout中来解决了这个问题。
<androidx.coordinatorlayout.widget.CoordinatorLayout>
    <androidx.constraintlayout.widget.ConstraintLayout
          <com.google.android.material.appbar.AppBarLayout
           </com.google.android.material.appbar.AppBarLayout
         //content here
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

我知道回复这个帖子有点晚了,但或许对其他人有帮助。 :)

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