【发布时间】:2018-09-13 08:48:17
【问题描述】:
我的应用:
我的根布局有底部导航栏,NavigationBar 的每个项目都对应一个FrameLayout,它加载带有ViewPagers 的片段,还有几个带有RecyclerViews 的片段。
我想在我的根布局中实现CollapsingToolbarLayout,当RecyclerView 在任何ViewPager 的Fragments 中滚动时,我想折叠折叠工具栏。
我的问题是,当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>
这是我的 viewpager 布局代码,它驻留在框架布局中调用的片段中:
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@+id/talesTabLayout"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/talesTabLayout"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
这是我在Fragment 布局中的RecyclerView:
<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>
我在Framelayout、ViewPager 和RecyclerView 中使用了“appbar_scrolling_view_behavior”属性,但没有成功。我用谷歌搜索了很多,但找不到任何关于这个特定问题的参考。任何形式的帮助将不胜感激!
【问题讨论】:
标签: android android-recyclerview android-viewpager android-coordinatorlayout android-framelayout