【发布时间】:2016-09-28 09:21:45
【问题描述】:
协调器布局有一些问题。我在 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中时,所有示例都存在。
我该如何解决?
【问题讨论】:
-
仍在寻找答案
-
请上,可以吗?
-
我也有类似的问题。会让你知道我发现了什么。
标签: android xml android-tablayout coordinator-layout