CoordinatorLayout 使用 ViewPager 的 RecyclerView [英] CoordinatorLayout using the ViewPager's RecyclerView

本文介绍了CoordinatorLayout 使用 ViewPager 的 RecyclerView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 android.support.design 中的视图 CoordinatorLayout.我想将 app:layout_behavior 附加到片段的 RecyclerView?

I am using the view CoordinatorLayout from android.support.design. I want to attach the app:layout_behavior to the fragment's RecyclerView?

在谷歌给出的例子中,他们只将它附加在 CoordinatorLayout 附加的同一个 XML 文件的 RecyclerView 中.

In the example given by Google, they only attach it in the RecyclerView of the same XML file where the CoordinatorLayout was attached.

有没有办法在 ViewPager 中将 CoordinatorLayout 附加到片段的 RecyclerView 上?

Is there a way to attach CoordinatorLayout to the fragment's RecyclerView within the ViewPager?

示例位于 Android 开发者博客的这篇博文中.

The sample is in this blog post at Android Developers blog.

推荐答案

Chris Banes 在 Github 上发布了一个示例,其中显示了您想要做什么.

Chris Banes has posted a sample on Github which shows exactly what you want to do.

这是定义如何将协调器布局间接附加到 viewpager 片段的 xml 文件.

Here is the xml file that defines how one can indirectly attach a coordinator layout to the viewpager's fragments.

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    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="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_done" />

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

这个想法是让 viewpager 拥有 layout_behavior 属性.

The idea is to let the viewpager have the layout_behavior attribute.

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

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