android - 使用折叠工具栏布局实现 RecyclerView

标签 android material-design android-recyclerview

我正在尝试使用折叠工具栏实现 RecyclerView,但我面临的问题是 RecyclerView 在折叠工具栏上向上移动。我想要实现的是它应该向下并出现折叠工具栏。
请帮忙?下面是我目前得到的结果的图像。

enter image description here

这里是我的代码

<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 所示。

您需要将此属性添加到 RecyclerView(或您希望在内容中作为父级的任何框架):

app:layout_behavior="@string/appbar_scrolling_view_behavior"

这将是您的 RecyclerView 的代码(除了 app:layout_behavior 属性外,您不需要添加任何其他内容):

<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"/>

关于android - 使用折叠工具栏布局实现 RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35155524/

相关文章:

java - 布局更改后设置 onClickListener 不起作用

javascript - 在 Ember.js 应用程序中初始化 Bootstrap Material Design

android - 带有工具栏的 NestedScrollView

java - RecyclerView 能否与其余 fragment 布局一起滚动?

java - fragment 中的 Recyclerview。 Activity 关闭后不更新

Android:Firebase remoteConfig getString() 方法正在从 default.xml 中的字符串中删除引号

android - 应用从错误的 Activity 中重启

Android获取星历数据和gnss测量

javascript - design.google.com 上的涟漪效应

javascript - 有没有办法在没有样式的情况下使用 Angular Material?