当TabLayout包含额外的非RecylerView组件时,我面临一个隐藏RecylerView的问题。
目前,我有以下布局。

在能够隐藏TabLayout之前
XML文件如下所示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" >
<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.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="?attr/portfolioTabIndicatorColor" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>以下组件属于ViewPager中的三个子片段中的一个。
这个ViewPager的子片段看起来像(更多的细节可以在https://gist.github.com/yccheok/da69b317e48af132f54c上找到)
ViewPager子片段布局
<LinearLayout>
<android.support.v7.widget.RecyclerView/>
<LinearLayout /> <!-- Footer -->
<LinearLayout /> <!-- Status bar -->
</LinearLayout>目前,只有RecylerView可以滚动。
其他组件,如Toolbar、TabLayout、LinearLayout Footer & LinearLayout Status Bar位置和大小都是静态的。
现在,我希望在滚动TabLayout时隐藏RecylerView。我指的是将TabLayout隐藏在内容卷轴上而不是ToolBar上
在能够隐藏TabLayout之后
<?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">
<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="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>结果不是我想要的,因为"LinearLayout页脚“和"LinearLayout状态栏”正在按下

但是滚动以隐藏TabLayout的一些工作原理。请参考下面的两个截图。


有可能吗?
TabLayout滚动时隐藏RecylerView。发布于 2016-03-24 06:58:53
通过以下教程,我能够实现我想要的
https://mzgreen.github.io/2015/02/15/How-to-hideshow-Toolbar-when-list-is-scroling%28part1%29/
http://mzgreen.github.io/2015/02/28/How-to-hideshow-Toolbar-when-list-is-scrolling%28part2%29/
关键的想法是
CoordinatorLayoutTabLayout和RecyclerView放置在FrameLayout中,这样TabLayout将覆盖在RecyclerView的顶部。RecyclerView上添加顶部填充。拥有android:clipToPadding="false"也很重要。TabLayout,请将HidingScrollListener附加到RecyclerView。该解决方案的缺点是,由于顶部填充,requiresFadingEdge将不再在RecyclerView上工作。
发布于 2016-03-16 16:48:11
根据我的理解,要实现这一点,您必须在活动xml中定义布局,而不是在视图寻呼机中定义片段。并使用可以更改LinearLayout和StatusBarLayout数据的接口将数据从片段传递到活动,您可以为LinearLayout和StatusBarLayout容器使用android:layout_gravity="bottom"将它们静态地放置在协调器布局的底部。
发布于 2016-03-17 01:50:48
在不使用循环视图的情况下。尝试使用支持库中可用的嵌套滚动视图包装视图。这将启用协调器布局的滚动行为。
https://stackoverflow.com/questions/36041197
复制相似问题