我的应用:
我的根布局有底部导航栏,NavigationBar
的每个项目对应一个FrameLayout
,用ViewPager
s加载片段,RecyclerView
s也有几个片段与CollapsingToolbarLayout
s。
我想在我的根布局中实现RecyclerView
,当ViewPager
在任何Fragment
的ViewPager
s中滚动时,我想折叠折叠工具栏。
我的问题是,当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>
的项目片段的布局中编写工具栏代码。
这是我的根布局代码:
<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">
这是我的viewpager布局代码,它位于在framelayout中调用的片段中:
RecyclerView
这是我在Fragment
布局中的<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>
:
appbar_scrolling_view_behavior
我在Framelayout
,ViewPager
和RecyclerView
中使用了“app:layout_scrollFlags="scroll|exitUntilCollapsed"
”属性但没有任何成功。我搜索了很多,但找不到任何关于这个特定问题的参考。任何形式的帮助将不胜感激!
首先使用CollapsingToolbarLayout
为CollapsingToolbarLayout
实现正确的行为。
我想在我的根布局中实现
RecyclerView
,当ViewPager
在任何Fragment
的Toolbar
s中滚动时,我想要折叠Toolbar
。
我没有在你的布局中看到任何AppBarLayout
s,但是,我假设你在app:layout_scrollFlags="scroll|enterAlways"
中使用它,这将有助于实现你想要的:
Toolbar
ViewPager
。我的问题是,当
CoordinatorLayout
是FrameLayout
的孩子时,我可以实现这种行为,但是当CoordinatorLayout
是FrameLayout
的孩子时不能。我需要实现Toolbar
否则我必须在每个BottomBar
项目Fragment
的布局中编写FrameLayout
代码。
在这种情况下使用CoordinatorLayout
(在Fragment
)似乎是最好的选择。
但是,我会做点别的。而不是在Fragment
或其他内部添加TabLayout
s,我会在Toolbar
下插入一个Fragment
,其中包含多个https://github.com/LinX64/AndroidSupportDesign-TabLayouts就像我的这个例子:qazxswpoi
这是应该如何设计的。不需要在彼此内部查看,这可能会导致问题。
漂亮的设计与那些边缘顺便说一下。