【问题标题】:RecyclerView wrapped inside CoordinatorLayout not resized when keyboard opens键盘打开时,包裹在 CoordinatorLayout 中的 RecyclerView 未调整大小
【发布时间】:2016-01-17 09:29:12
【问题描述】:

活动布局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>

recycler_view 的单元格包含 EditText。当我选择 EditText 时,SoftKeyboard 会打开,但 EditText 隐藏在键盘后面。

我在活动中添加了以下标志:

android:windowSoftInputMode="adjustResize"

我正在使用 23.1.1 appcompat 版本的 RecyclerView。

当我用 LinearLayout 替换 CoordinatorLayout 时,RecyclerView 正在调整大小以正确显示最后一个元素。所以我认为这是协调器布局的问题。

我经历了以下问题 https://code.google.com/p/android/issues/detail?id=176406https://code.google.com/p/android/issues/detail?id=176187 但它与此错误无关。让我知道我是否可以应用一些方法来解决这个问题。

等待回复。谢谢。 如果需要更多详细信息,请告诉我。

【问题讨论】:

  • 我努力修复它。最后,我为它创建了 Android 问题。我分享了我的虚拟项目来说明问题。检查以下链接以了解问题状态:code.google.com/p/android/issues/…
  • @streamride 不,我无法修复它。 l 更改了设计以解决问题。

标签: android android-layout android-recyclerview android-coordinatorlayout


【解决方案1】:

有一个非常相似的问题,并且能够通过使用 android:windowSoftInputMode="adjustPan" 解决它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 2019-01-17
    • 2021-10-16
    • 2015-11-04
    • 2016-10-11
    • 2019-11-17
    • 1970-01-01
    相关资源
    最近更新 更多