CoordinatorLayout + FrameLayout + ViewPager + RecyclerView

问题描述 投票:1回答:1

我的应用:

enter image description here我的根布局有底部导航栏,NavigationBar的每个项目对应一个FrameLayout,用ViewPagers加载片段,RecyclerViews也有几个片段与CollapsingToolbarLayouts。

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

我的问题是,当CoordinatorLayoutFrameLayout的孩子时,我可以实现这种行为,但是当CoordinatorLayoutFrameLayout的孩子时不能。我需要实现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

我在FramelayoutViewPagerRecyclerView中使用了“app:layout_scrollFlags="scroll|exitUntilCollapsed"”属性但没有任何成功。我搜索了很多,但找不到任何关于这个特定问题的参考。任何形式的帮助将不胜感激!

android android-recyclerview android-viewpager android-coordinatorlayout android-framelayout
1个回答
0
投票

首先使用CollapsingToolbarLayoutCollapsingToolbarLayout实现正确的行为。

我想在我的根布局中实现RecyclerView,当ViewPager在任何FragmentToolbars中滚动时,我想要折叠Toolbar

我没有在你的布局中看到任何AppBarLayouts,但是,我假设你在app:layout_scrollFlags="scroll|enterAlways" 中使用它,这将有助于实现你想要的:

Toolbar
  • 在根布局中添加ViewPager

我的问题是,当CoordinatorLayoutFrameLayout的孩子时,我可以实现这种行为,但是当CoordinatorLayoutFrameLayout的孩子时不能。我需要实现Toolbar否则我必须在每个BottomBar项目Fragment的布局中编写FrameLayout代码。

在这种情况下使用CoordinatorLayout(在Fragment)似乎是最好的选择。


但是,我会做点别的。而不是在Fragment或其他内部添加TabLayouts,我会在Toolbar下插入一个Fragment,其中包含多个https://github.com/LinX64/AndroidSupportDesign-TabLayouts就像我的这个例子:qazxswpoi

这是应该如何设计的。不需要在彼此内部查看,这可能会导致问题。

漂亮的设计与那些边缘顺便说一下。

© www.soinside.com 2019 - 2024. All rights reserved.