CoordinatorLayout与RecyclerView和折叠头 [英] CoordinatorLayout with RecyclerView And Collapsing header

查看:1515
本文介绍了CoordinatorLayout与RecyclerView和折叠头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似下面的布局:

在这里输入的形象描述

(工具栏,
标题视图,文本视图,RecyclerView)

(Toolbar, Header View, Text View, RecyclerView)

我需要折叠头,当我滚动recyclerview的项目。
这样的观点选择项,并留下recyclerview在屏幕上。

I need the header to be collapsed when I scrolling recyclerview's items. So that the view "Choose item" and recyclerview left on the screen.

我看到的例子工具栏被倒塌的时候,但我需要的工具栏是present始终。

I saw examples when toolbar is being collapsed, but I need toolbar to be present always.

我应该使用哪些布局/行为得到这个工作的?

Which layouts/behavior should I use to get this work?

推荐答案

您可以通过让此布局存档:

You can archive it by having this layout:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <!-- HEADER -->
            <RelativeLayout
                ...
                app:layout_collapseMode="parallax">
                .....
            </RelativeLayout>

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

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

       <!-- IF YOU WANT TO KEEP "Choose Item" always on top of the RecyclerView, put this TextView here
        <TextView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_gravity="bottom"
             android:text="choose item" />
       -->
    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

您通过让应用针工具栏:layout_collapseMode =针属性集。你让 RecyclerView 正常滚动通过设置应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior,这就是pretty多吧。

You pin your toolbar by having app:layout_collapseMode="pin" property set. You make RecyclerView properly scrollable by setting app:layout_behavior="@string/appbar_scrolling_view_behavior" and that's pretty much it.

NB 的选择项位置的TextView 依赖于特定的行为你要存档:

NB! Position of "Choose item" TextView depends on the particular behaviour your want to archive:


  • 您可以把它作为第一要素你的 RecyclerView 适配器滚动它扔掉,一旦用户开始滚动通过 RecyclerView ;

  • 您可以将其添加到 AppBarLayout 所以它会一直坚持对的 RecyclerView ,当你滚动顶部与否;

  • you can include it as a first element of your RecyclerView's Adapter to scroll it away, once user start scrolling through the RecyclerView;
  • you can add it into AppBarLayout so it'd always stick on top of the RecyclerView, whenever you scroll it or not;

您可以在这里阅读更多 Android设计支持库这里设计支持库(III):协调布局

You can read more here Android Design Support Library and here Design Support Library (III): Coordinator Layout

我希望它能帮助!

这篇关于CoordinatorLayout与RecyclerView和折叠头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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