【问题标题】:hide/show tab bar/tab layout on scrolling in coordinator layout在协调器布局中滚动时隐藏/显示选项卡栏/选项卡布局
【发布时间】:2016-06-03 01:01:57
【问题描述】:

我想在协调器布局中向上/向下滚动时隐藏/显示标签栏(不是操作栏)。 我已经尝试实现用于操作栏的相同技术,但没有成功

这是我的xml代码sn-p

<android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


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

                <android.support.v7.widget.Toolbar
                    android:id="@+id/drawer_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="?attr/colorPrimaryDark"
                    android:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    app:layout_scrollFlags="scroll"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                    android:layout_width="match_parent"
                    android:background = "?attr/colorPrimaryDark"
                    android:layout_height="wrap_content"

                    />

            </android.support.design.widget.AppBarLayout>

它适用于应用栏,但不适用于标签栏。 如何做到这一点? 请指教?

编辑:我只希望标签栏滚动而不是应用栏。

【问题讨论】:

    标签: android xml android-layout


    【解决方案1】:

    必须启用属性 app:layout_scrollFlags 中使用的滚动标志才能使任何滚动效果生效。此标志必须与 enterAlways、enterAlwaysCollapsed、exitUntilCollapsed 或 snap 一起启用。

    你可以结合使用

    app:layout_scrollFlags="scroll|exitUntilCollapsed"

    Check out this guide.

    【讨论】:

    • 工作正常,但我希望只滚动标签栏而不是应用栏。
    【解决方案2】:

    也许将高度(和最小高度)设置为:?attr/actionBarSize

            <android.support.v7.widget.Toolbar
                android:id="@+id/drawer_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimaryDark"
                android:popupTheme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
    

    【讨论】:

    • 仍然没有变化。标签栏要么与应用栏一起滚动,要么根本不滚动。
    猜你喜欢
    • 2017-08-22
    • 2019-04-28
    • 2016-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 2021-08-10
    相关资源
    最近更新 更多