Toolbar does not crash with RecyclerView

2

I have an activity in which I use a RecyclerView, I am trying to make the Android bar collapse when I scroll over the RecyclerView, I have tried using NestedScrollView, but having many elements in the RecyclerView slowed down the activity.

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        app:contentScrim="@color/semi_transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:contentDescription="@string/background"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            android:background="?attr/nav_background_drawable"
            android:id="@+id/background"
            app:layout_collapseMode="parallax"/>


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

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


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

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".myactivity"
    android:id="@+id/recycler"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="50dp"
    android:layout_marginEnd="@dimen/fab_margin"
    android:layout_marginRight="@dimen/fab_margin"
    android:src="@drawable/ic_crono"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|end"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_charts"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="50dp"
    android:layout_marginStart="@dimen/fab_margin"
    android:layout_marginLeft="@dimen/fab_margin"
    android:src="@drawable/ic_chart"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|left|start"/>

    
asked by Pelayo Rodriguez 16.08.2016 в 20:40
source

2 answers

1

There are several reasons, the first, a known bug that was fixed in version 23.1.0:

link

Another cause is that you do not have the property app:layout_scrollFlags and the flag scroll defined in CollapsingToolbarLayout :

app:layout_scrollFlags="scroll"

Another cause that is explicitly not allowed to scroll in your RecyclerView: , so it must be enabled:

mRecyclerView.setNestedScrollingEnabled(true)
    
answered by 17.08.2016 / 10:57
source
2

I found the problem I had:

mRecyclerView.setNestedScrollingEnabled(false)

And I changed to:

mRecyclerView.setNestedScrollingEnabled(true)
    
answered by 16.08.2016 в 22:48