CollapsingToolbarLayout + Coordinatorlayout + ViewPager + Fragment

问题描述:

我已经搜索过,但似乎没有像我的类似问题。CollapsingToolbarLayout + Coordinatorlayout + ViewPager + Fragment

我有一个ViewPager与几个片段。在每个片段中,当下面的部分滚动时(通常是RecylcerView),会有一个标题部分让我想要它折叠(pallax)。 Collapsing部分是另一个片段(所以我可以在几个地方重复使用)。

具有此布局的第一个片段(在ViewPager中)工作正常(图片A)。但是,其他人会有像图片B这样的问题。当您在ViewPager中更改片段的顺序时,例如B到第一,A到第二,然后A将得到问题,B将正常工作。

甲工作正常(A是在ViewPager第一片段) Pic A

B具有重叠的问题。有一个在顶部的空间,底部由列表重叠低于 Pic B

当向上滚动以下reclyclerview,顶部不完全崩溃

这里是布局,既是& B使用同样的布局

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/app_bar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:fitsSystemWindows="true" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_collapseMode="parallax" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"> 

      <fragment 
       android:id="@+id/fragment_test" 
       android:name="com.sample.android.fragment.FragmentTest" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/test_height" 
       android:fitsSystemWindows="true" 
       app:layout_collapseMode="parallax" /> 
     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

    <include 
     layout="@layout/layout_list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/tv_emtpy" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</android.support.design.widget.CoordinatorLayout> 
  • layout_list只包含一个RecyclerView

PS:我曾尝试几种方法: - 安卓fitsSystemWindows为AppBarLayout,CoordinatorLayout ... - 将列表分为AppBarLayout

我还挺面临同样的问题;与坐标布局的错误。 给这个图书馆一个尝试,示例应用程序也在PlayStore上。

https://github.com/henrytao-me/smooth-app-bar-layout 

你将不得不修改viewPager和适配器,我也猜测; 但整合不应该花很长时间。 首先通过游戏商店的示例应用程序,并确定它是否会对你有所帮助。

https://play.google.com/store/apps/details?id=me.henrytao.smoothappbarlayout 
+0

感谢您的建议。我会试一试,尽管看起来没有任何选项与我的设计相似(查看寻呼机片段内的折叠区域并且本身就是片段) –

+0

供参考:图书馆无助于解决问题。实际上,当布局向上滚动时,会导致另一个闪烁问题。我想我必须为此布局使用另一种策略。还是)感谢你的建议 –