将Recycler锚定在折叠的工具栏布局上高一点 [英] Anchor a RecyclerView little higher on a Collapsing Toolbar Layout

本文介绍了将Recycler锚定在折叠的工具栏布局上高一点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将RecyclerView锚定在比通常位置高一点的位置,就像大多数可折叠视图中的FAB图标一样(预期效果请参见图1).

Is it possible to anchor a RecyclerView a little bit higher than it's usual location, Like the FAB icon on most of the collapsible views (see Image 1 for the expected results).

图片1

我尝试了以下代码,但是没有给出预期的结果(有关当前结果,请参见图2)

I tried the following code but it doesn't give the expected result (see Image 2 for the current result)

<android.support.design.widget.CoordinatorLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="180dp"
    android:fitsSystemWindows="true"
    app:expanded="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleTextAppearance="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/bannerImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            android:src="@drawable/starter_screen_bg"/>

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

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/categories"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:gravity="center"
        >
    </android.support.v7.widget.RecyclerView>

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

图片2

添加app:layout_behavior="@string/appbar_scrolling_view_behavior"将回收者视图附加到可折叠视图,然后忽略添加边距底部.

Adding app:layout_behavior="@string/appbar_scrolling_view_behavior" attaches the recycler view to the Collapsible View, and then adding margin bottom is neglected.

但是将其删除会得到预期的结果,但是滚动视图的行为不符合预期(无视差效果),并且在背景图像滚动后仍会滚动.

But removing it gives the expected result, but then the scroll view does not behave as intended (no parallax effect) and scroll's after the background image scrolls.

因此可以实现像第一张图片一样的可折叠视图.

So it is possible to achieve the collapsible view like the first image.

推荐答案

这实际上很容易实现-每个具有app:layout_behavior="@string/appbar_scrolling_view_behavior"的视图都有一个behavior_overlapTop属性.因此,您只需要将此属性设置为您的RecyclerView:

This is actually pretty easy to achieve - there is a behavior_overlapTop property for each view that has app:layout_behavior="@string/appbar_scrolling_view_behavior". So all you need to do is just to set this property to your RecyclerView:

<android.support.v7.widget.RecyclerView
    android:id="@+id/categories"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    app:behavior_overlapTop="64dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:gravity="center"/>

这篇关于将Recycler锚定在折叠的工具栏布局上高一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆