【发布时间】:2016-07-06 00:46:33
【问题描述】:
我倾向于从这里进一步阐述
Android - footer scrolls off screen when used in CoordinatorLayout
和
https://code.google.com/p/android/issues/detail?id=177195
我希望在滚动 RecyclerView 时隐藏 TabLayout。这就是为什么我有以下布局。
<CoordinatorLayout>
<CollapsingToolbarLayout>
<TabLayout>
<ViewPager>
<RecyclerView>
<Footer>
对于我的情况,我有一个ViewPager,其中包含多个片段。
大部分片段,包含RecyclerView 和页脚。它们如下所示
<LinearLayout>
<RecyclerView />
<LinearLayout id="@+id/footer" />
</LinearLayout>
不幸的是,页脚在滚动时是可移动的,尽管我希望它是静态的。
请注意,将app:layout_behavior 放置在ViewPager 而不是RecyclerView 中很重要。如果没有,TabLayout 将不会出现。
我的实现如下
my_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" >
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="?attr/portfolioTabIndicatorColor" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="org.yccheok.xxx.CustomScrollingViewBehavior"
/>
</android.support.design.widget.CoordinatorLayout>
非常关键的类是org.yccheok.xxx.CustomScrollingViewBehavior,从https://stackoverflow.com/a/33396965/72437复制粘贴
org.yccheok.xxx.CustomScrollingViewBehavior 是迄今为止我能找到的最佳解决方案。但是,它远非完美,因为它会产生以下行为。
当您向上滚动一点并松开手指时,它会导致闪烁。请参考以下视频。
我想知道,根据https://stackoverflow.com/a/33396965/72437 提出的解决方案,我是否可以对CustomScrollingViewBehavior 类进行进一步改进以避免闪烁效果?
【问题讨论】:
标签: android