Android – implement recyclerview using a collapsed toolbar layout

I'm trying to implement recyclerview using the folding toolbar, but I'm facing a problem because recyclerview is up on the folding toolbar. I want to implement it by closing and displaying the folding toolbar. Please help? Here are my current results

My code

<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"
tools:context="sccs.android.com.userinformation.HomeScreen">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    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/collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="325dp"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"

        app:layout_scrollFlags="scroll|exitUntilCollapsed">
        <ImageView
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@mipmap/nature2"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="top"
            android:minHeight="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView
    android:layout_below="@+id/appbar"
    android:padding="10dp"
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>


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

resolvent:

As @shijil shown

You need to add this attribute to recyclerview (or any frame you want to parent in content):

app:layout_behavior="@string/appbar_scrolling_view_behavior"

This will be your recyclerview code (you don't need to add anything except the app: layout_behavior attribute):

<android.support.v7.widget.RecyclerView
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_below="@+id/appbar"
    android:padding="10dp"
    android:id="@+id/my_recycler_view"
    android:scrollbars="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>