首页 > 解决方案 > 由于 RecyclerView,Scrollview 在 CollapsingToolbarLayout 下方滚动

问题描述

我有一个详细的活动,在我的应用程序中显示游戏的详细信息。布局主要由CollapsingToolbarLayout带有游戏封面的a和NestedScrollView包含细节的a组成。布局是这样的: 1 并且像这样滚动: 2 布局的 XML 文件是:

<android.support.design.widget.CoordinatorLayout 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/game_detail_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".activities.GameDetailActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <ImageView
                android:id="@+id/toolbar_cover"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/game_cover"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/scrim" />

            <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/AppTheme.PopupOverlay" />

        </net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        app:srcCompat="@drawable/ic_favorite_border_black_24dp" />

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

而且content_game_detail是:

<android.support.v4.widget.NestedScrollView 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/game_detail_scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".activities.GameDetailActivity"
    tools:showIn="@layout/activity_game_detail">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- There are 11 TextViews here for all the info -->

        <android.support.v7.widget.RecyclerView
            android:id="@+id/videos_recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/simple_margin"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/videos_lable" />

    </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>

问题是:当摘要很长并且有视频可以添加项目时RecyclerView,布局开始在展开的工具栏下方稍微滚动,如下所示:

3

我需要向下滚动视图以查看信息的顶部。测试,我将问题缩小到RecyclerView. 当我删除它时,这个问题不会发生。似乎当将项目添加到时RecyclerView,布局本身会向上滚动以进行补偿,但我找不到为什么会发生这种情况(而不是只是向下扩展视图),也找不到解决方法。有人有什么主意吗?

标签: androidandroid-layoutandroid-recyclerviewandroid-collapsingtoolbarlayout

解决方案


推荐阅读