Android 协调布局+;框架布局+;ViewPager+;回收视图

Android 协调布局+;框架布局+;ViewPager+;回收视图,android,android-recyclerview,android-viewpager,android-coordinatorlayout,android-framelayout,Android,Android Recyclerview,Android Viewpager,Android Coordinatorlayout,Android Framelayout,我的应用程序: 我的根布局具有底部导航栏,NavigationBar的每一项都对应于一个FrameLayout,该布局使用ViewPagers加载片段,该视图也使用RecyclerViews加载多个片段 我想在我的根布局中实现一个折叠工具栏布局,当回收视图在任何查看页面的片段中滚动时,我想折叠工具栏 我的问题是,当ViewPager是CoordinatorLayout的子对象时,我可以实现此行为,但当FrameLayout是CoordinatorLayout的子对象时,我无法实现此行为。我需要

我的应用程序:

我的根布局具有底部导航栏,
NavigationBar
的每一项都对应于一个
FrameLayout
,该布局使用
ViewPager
s加载片段,该视图也使用
RecyclerView
s加载多个片段

我想在我的根布局中实现一个
折叠工具栏布局
,当
回收视图
在任何
查看页面
片段
中滚动时,我想折叠工具栏

我的问题是,当
ViewPager
CoordinatorLayout
的子对象时,我可以实现此行为,但当
FrameLayout
CoordinatorLayout
的子对象时,我无法实现此行为。我需要实现
FrameLayout
,否则我必须在每个
BottomBar
项片段的布局中编写工具栏代码

这是我的根布局代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#4DBC76"
            app:elevation="0dp">

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

                <android.support.constraint.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="60dp">

                </android.support.constraint.ConstraintLayout>

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


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

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="125dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:id="@+id/testRootFragment"
            >
        </FrameLayout>


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

    <bd.com.xbit.eat.bottom_navigation
        android:id="@+id/bottomNavigationViewTest"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        app:elevation="25dp"
        app:itemTextColor="@drawable/bottom_selector"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_navigation" />

</android.support.constraint.ConstraintLayout>

我在
Framelayout
ViewPager
RecyclerView
中使用了“
appbar\u scrolling\u view\u behavior
”属性,但没有成功。我在谷歌上搜索了很多,但找不到关于这个问题的任何参考资料。任何形式的帮助都将不胜感激

首先使用
app:layout\u scrollFlags=“scroll | exituntilclopsed”
来实现正确的行为

我想在我的根布局中实现一个
折叠工具栏布局
当在任何
ViewPager
片段中滚动
RecyclerView
时, 我想折叠
工具栏

我在您的布局中没有看到任何
工具栏
s,但是,我假设您在
AppBarLayout
中使用了它,这将有助于实现您想要的:

app:layout_scrollFlags="scroll|enterAlways"
  • 在根布局中添加
    工具栏
我的问题是,当
ViewPager
是子对象时,我可以实现此行为 属于
协调布局
,但当
框架布局
协调布局
。我需要实现
FrameLayout
,否则我必须 在每个
BottomBar
的项目
片段
的布局中写入
工具栏
代码

在这种情况下使用
FrameLayout
协调布局中的)似乎是最佳选择


不过,我想做点别的。我不想在
Fragment
中添加
Fragment
或任何东西,而是在
工具栏下插入一个
TabLayout
,它包含多个
Fragment
就像我的示例:

这就是它应该如何设计的。互不需要视图,这可能会导致问题


顺便说一句,这些边的设计很好。

非常感谢您的建议。我的问题是我的根布局有由底部栏初始化的片段,这些片段有ViewPager,其中也有带有recyclerview的片段。因此,我尝试在根目录中使用具有可滚动行为的framelayout。否则我一定会以你为榜样。
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tales_all_recyclerView"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >

</android.support.v7.widget.RecyclerView>
app:layout_scrollFlags="scroll|enterAlways"