0

我对协调器布局有一些问题。我在 appBarLayout 中有带有父 CoordinatorLayout 的活动工具栏(我想让工具栏可隐藏),在 appBarLayout 和 viewPager 中有带有 tablayout 的片段。这是活动的 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:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="@drawable/gradient"
   android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
       android:id="@+id/toolbar_container"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
           android:id="@+id/toolbar"
           android:layout_width="match_parent"
           android:layout_height="?attr/actionBarSize"
           android:background="?attr/colorPrimary"
           app:layout_scrollFlags="scroll|enterAlways|snap"
           app:popupTheme="@style/AppTheme.PopupOverlay"/>

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

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/content"
       android:layout_width="match_parent"
       android:layout_height="match_parent" />

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

它是片段的 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:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="@drawable/gradient"
   android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       android:id="@+id/toolbar_container"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.TabLayout
           android:id="@+id/tabs"
           style="@style/MyCustomTabLayout"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           app:tabGravity="fill"/>

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

    <android.support.v4.view.ViewPager
       android:id="@+id/viewPager"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

现在,我遇到了工具栏在某处的情况。 没有工具栏

如果我将活动中的协调器布局更改为线性布局,我会看到工具栏可见,但正如您可以想象的那样,没有隐藏选项。

实际上,我经常使用协调器布局:在视差和其他情况下隐藏和显示工具栏 - https://github.com/Iamtodor/toolbars,所以你可以肯定,我有点了解它是如何工作的:)

另外,我想要这个来源: - https://github.com/codepath/android_guides/wiki/Handling-Scrolls-with-CoordinatorLayout - https://github.com/codepath/android_guides/wiki/Using-the-App -ToolBar#using-toolbar-as-actionbar - https://github.com/chrisbanes/cheesesquare

但是,当 tablayout 存在于与工具栏相同的 appbarlayout 中时,所有示例都存在。

我该如何解决?

4

1 回答 1

0

这对我有用:

片段 XML:

<android.support.design.widget.AppBarLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:elevation="0dp">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways|snap" >

        <include layout="@layout/include_time_line"
            android:layout_height="wrap_content"
            android:layout_width="match_parent" />
    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        style="@style/TabLayout"
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="54dp"
        android:layout_gravity="bottom"
        android:background="@color/egg"
        android:elevation="0dp"
        app:tabGravity="fill"
        app:tabMode="scrollable"
        app:tabIndicatorColor="#fcd131"
        app:tabPadding="0dp"
        app:tabIndicatorHeight="4dp"/>
</android.support.design.widget.AppBarLayout>

<com.woot.woot.productbrowse.ui.ConfigurablePagingViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    />
<FrameLayout
    android:id="@+id/selectByWeightKeyboard"
    android:layout_width="match_parent"
    android:layout_height="@dimen/weight_keyboard_container_height"
    android:background="@color/keyboard"
    android:clipToPadding="false"
    android:elevation="16dp"
    android:clickable="true"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

    <include layout="@layout/add_product_by_weight_keyboard" />
</FrameLayout>

活动 XML:

    <FrameLayout
        android:id="@+id/contentFrame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <FrameLayout
        android:id="@+id/layout_done_button"
        android:visibility="gone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:elevation="8dp"
        tools:visibility="visible"
        android:background="@color/ice">

        <Button
            android:id="@+id/button_done"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="match_parent"
            android:layout_height="@dimen/button_height"
            android:layout_marginRight="@dimen/button_done_horizontal_margin"
            android:layout_marginLeft="@dimen/button_done_horizontal_margin"
            android:layout_marginTop="@dimen/activity_horizontal_margin"
            android:layout_marginBottom="@dimen/activity_horizontal_margin"
            android:background="@drawable/rounded_green_button"
            android:text="@string/done"
            android:textSize="@dimen/button_text_size"
            android:textAllCaps="true"
            android:textColor="@color/egg" />
    </FrameLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:contentDescription="@string/drawer_content_description"
    app:menu="@menu/menu_navigation_product_browse" />

于 2018-02-14T01:44:28.620 回答