使用折叠的工具栏布局实现RecyclerView [英] Implementing RecyclerView with collapsing toolbar layout
问题描述
我正在尝试使用折叠的工具栏实现RecyclerView,但是当RecyclerView出现在折叠的工具栏上时,我正面临问题.我想实现的目标是关闭它并附带折叠的工具栏.
请帮忙?下面是我目前正在得到结果的图像.
I'm trying to implement RecyclerView with collapsing toolbar,but i'm facing the problem as RecyclerView comes upward on collapsing toolbar.What i want to acheive that it should be down and comes up with collapsing toolbar.
please help? Below is the image what i'm currently getting the result.
这里是我的代码
<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>
推荐答案
如@shijil所示.
As @shijil showed.
您需要将此属性添加到RecyclerView(或您要作为其内容父级的任何框架):
You need to add this attribute to the RecyclerView (or any frame you want to have as the parent in your content):
app:layout_behavior="@string/appbar_scrolling_view_behavior"
这将是您的RecyclerView的代码(除了app:layout_behavior
属性之外,您无需添加其他任何内容):
This would be your RecyclerView's code (You don't need to add anything else besides 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"/>
这篇关于使用折叠的工具栏布局实现RecyclerView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!