使用RecyclerView滚动时,CollapsingToolbarLayout不会折叠

时间:2016-03-22 23:12:23

标签: android xml

我使用CollapsingToolbarLayout作为折叠工具栏,它在大多数情况下都有效。当您开始在RecyclerView之外的页面的任何部分滚动时,它将滚动正常,工具栏将按照它应该的方式折叠。但是,当您开始在RecyclerView上滚动时,它不会折叠工具栏并且看起来不是最好。

我尝试了许多我在网上找到的不同解决方案,似乎没有任何帮助。我正在使用appcompat-v7:23.2.1。这是布局文件的样子:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/movie_detail_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/movie_detail_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay"/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <!-- Movie Content here -->
    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <LinearLayout
            android:padding="16dp"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <RelativeLayout
                    android:id="@+id/movie_detail_out_yet_layout"
                    android:layout_marginRight="10dp"
                    android:layout_marginEnd="10dp"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    tools:background="@drawable/green_square">
                    <ImageView
                        android:id="@+id/movie_detail_out_yet_image_view"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        tools:src="@drawable/ic_checkmark"/>
                </RelativeLayout>

                <TextView
                    android:layout_toRightOf="@+id/movie_detail_out_yet_layout"
                    android:layout_toEndOf="@+id/movie_detail_out_yet_layout"
                    android:id="@+id/movie_detail_release_date"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    style="?android:attr/textAppearanceMedium"
                    tools:text="March 21, 2016"/>

                <TextView
                    android:layout_marginLeft="20dp"
                    android:layout_marginStart="20dp"
                    android:id="@+id/movie_detail_mpaa_rating"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    style="?android:attr/textAppearanceMedium"
                    android:textStyle="bold"
                    tools:text="PG-13"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"/>
            </RelativeLayout>

            <TextView
                android:layout_marginTop="16dp"
                style="?android:listSeparatorTextViewStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/h_plot"/>

            <TextView
                android:layout_marginTop="5dp"
                android:id="@+id/movie_detail_plot"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>

            <TextView
                android:layout_marginTop="16dp"
                style="?android:listSeparatorTextViewStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/h_ratings"/>

            <TextView
                android:id="@+id/movie_detail_no_ratings_tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="@string/unknown"
                android:visibility="gone"/>

            <LinearLayout
                android:orientation="horizontal"
                android:id="@+id/movie_detail_rating_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <!-- Critics Section -->
                <LinearLayout
                    android:layout_weight="0.5"
                    android:orientation="horizontal"
                    android:layout_width="0dp"
                    android:layout_height="match_parent">
                    <TextView
                        android:id="@+id/movie_detail_critics_rating_box"
                        android:layout_marginTop="5dp"
                        tools:background="@drawable/orange_square"
                        tools:text="6.7"
                        android:textColor="@android:color/white"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>
                    <TextView
                        android:layout_gravity="center_vertical"
                        android:id="@+id/movie_detail_critics_rating_tv"
                        android:layout_marginLeft="5dp"
                        android:layout_marginStart="5dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="?android:attr/textAppearanceMedium"
                        android:text="@string/critics_rating"/>
                </LinearLayout>

                <!-- Audience Section -->
                <LinearLayout
                    android:layout_weight="0.5"
                    android:layout_width="0dp"
                    android:layout_height="match_parent">
                    <TextView
                        android:id="@+id/movie_detail_audience_rating_box"
                        android:layout_marginTop="5dp"
                        tools:background="@drawable/orange_square"
                        tools:text="6.7"
                        android:textColor="@android:color/white"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>
                    <TextView
                        android:layout_gravity="center_vertical"
                        android:layout_marginLeft="5dp"
                        android:layout_marginStart="5dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        style="?android:attr/textAppearanceMedium"
                        android:text="@string/audience_rating"/>
                </LinearLayout>
            </LinearLayout>

            <TextView
                android:layout_marginTop="16dp"
                style="?android:listSeparatorTextViewStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/h_cast"/>

            <TextView
                android:id="@+id/movie_detail_no_cast_tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                style="?android:textAppearanceMedium"
                android:text="@string/unknown"
                android:visibility="visible"/>

            <android.support.v7.widget.RecyclerView
                android:id="@+id/movie_detail_cast_member_rv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:visibility="gone"/>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

对于RecyclerView,我将其设置为具有LinearLayoutManager和我的自定义适配器。任何帮助都会很棒,已经过了几个星期,我仍然无法解决这个问题。

Scroll issue

编辑:似乎只在向上滚动时发生。如果工具栏折叠并向下滚动,它会像应该的那样展开。但是,和以前一样,向上滚动它似乎不起作用。

0 个答案:

没有答案