Android 当ViewPager包含其他非RecyclerView组件时,如何隐藏TableLayout

Android 当ViewPager包含其他非RecyclerView组件时,如何隐藏TableLayout,android,android-layout,Android,Android Layout,当ViewPager包含其他非recyleView组件时,我面临隐藏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-au

ViewPager
包含其他非
recyleView
组件时,我面临隐藏
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>
目前,只有
RecylerView
可滚动

其他组件,如
工具栏
表格布局
线性布局页脚
&
线性布局状态栏
位置和大小是静态的

现在我想在滚动查看时隐藏
TabLayout
。我指的是


在能够隐藏表格布局之后

但滚动至隐藏
TabLayout
一些工作原理。请参阅下面的2个屏幕截图

可能吗

  • 继续使LinearLayout页脚和LinearLayout状态栏成为ViewPager子片段布局的一部分
  • 将LinearLayout页脚和LinearLayout状态栏的位置设置为静态
  • 执行
    RecylerView
    滚动时,可以隐藏
    TabLayout

  • 根据我的理解,要实现这一点,您必须在活动xml中定义布局,而不是在视图页面中定义片段。并使用一个可以更改LinearLayout和StatusBarLayout数据的接口将数据从片段传送到活动,您可以使用android:layout\u gravity=“bottom”
    用于您的LinearLayout和StatusBarLayout容器,将它们静态放置在协调器布局的底部。

    在不使用回收视图的情况下。尝试使用支持库中提供的嵌套滚动视图包装视图。这将启用协调器布局的滚动行为。

    我能够通过以下教程实现我想要的

    关键思想是

  • 不要使用
    CoordinatorLayout
  • TabLayout
    RecyclerView
    放在
    FrameLayout
    中,这样
    TabLayout
    将覆盖在
    RecyclerView
  • RecyclerView
    上添加顶部填充。拥有android:clipToPadding=“false”也很重要
  • 要在滚动期间隐藏/显示
    TabLayout
    ,请附加到
    RecyclerView
  • 此解决方案的缺点是,
    requiresFadingEdge
    由于顶部填充而不再适用于
    RecyclerView

    <LinearLayout>
        <android.support.v7.widget.RecyclerView/>
        <LinearLayout /> <!-- Footer -->
        <LinearLayout /> <!-- Status bar -->
    </LinearLayout>
    
    <?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>