折叠工具栏布局,表格布局不展开或显示选项卡



我正在尝试将一个折叠工具栏添加到我的现有活动中,该活动在自定义框架布局中包含TabLayout。从我在下面尝试的内容来看,当滚动到顶部时,工具栏并没有完全展开,而是消失了。TabLayout也不会出现在任何地方。

这是我所拥有的:

<org.corey.android.common_ui.CustomFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                               xmlns:app="http://schemas.android.com/apk/res-auto"
                                               xmlns:tools="http://schemas.android.com/tools"
                                               android:layout_width="match_parent"
                                               android:layout_height="wrap_content"
                                               tools:context=".TestActivity"
                                               tools:ignore="MergeRootFrame">
    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="256dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">
                <android.support.design.widget.TabLayout
                    android:id="@+id/test_tab_layout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:background="@color/white"
                    android:minHeight="?attr/actionBarSize"
                    />

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_collapseMode="parallax" />
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
        <RelativeLayout
            android:id="@+id/test_content_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white">
            <android.support.v4.view.ViewPager
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/button_container"
                />
            <FrameLayout
                android:id="@+id/button_container"
                android:layout_width="match_parent"
                android:layout_height="@dimen/test_activity_bottom_button_height"
                android:layout_alignParentBottom="true"
                android:background="@color/green_success"
                android:visibility="gone">
                <Button
                    android:id="@+id/button"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="?android:attr/selectableItemBackground"
                    android:textColor="@android:color/white" />
            </FrameLayout>
            <FrameLayout
                android:id="@id/bottom_button_container"
                android:layout_width="match_parent"
                android:layout_height="@dimen/bottom_button_height"
                android:layout_alignParentBottom="true"
                android:background="@color/backgroundDark"
                android:visibility="gone">
                <Button
                    android:id="@+id/button"
                    style="@style/Dark.Button.Primary"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="?android:attr/selectableItemBackground"
                    android:textColor="@android:color/white" />
            </FrameLayout>
            <ProgressBar
                android:id="@+id/loading"
                android:layout_centerInParent="true"
                android:visibility="gone"
                style="@style/progress_bar_standard"/>
        </RelativeLayout>
    </android.support.design.widget.CoordinatorLayout>
</org.corey.android.common_ui.CustomFrameLayout> 

我正在尝试实现这样的事情:https://gist.github.com/iPaulPro/1468510f046cb10c51ea

在此处使用match_parent

<org.corey.android.common_ui.CustomFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                               xmlns:app="http://schemas.android.com/apk/res-auto"
                                               xmlns:tools="http://schemas.android.com/tools"
                                               android:layout_width="match_parent"
                                               android:layout_height="match_parent"
                                               tools:context=".TestActivity"
                                               tools:ignore="MergeRootFrame">

然后使用 app:layout_behavior="@string/appbar_scrolling_view_behavior" 作为您的相对布局

 <RelativeLayout
            android:id="@+id/test_content_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior
            android:background="@color/white">

3:如果要将选项卡放在工具栏下方,请使用重力

 <android.support.design.widget.TabLayout
                android:id="@+id/test_tab_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:background="@color/white"
                android:layout_gravity="bottom"
                android:minHeight="?attr/actionBarSize"
                />

最新更新