簡體   English   中英

即使 CollapsingToolbarLayout 折疊,如何使 Toolbar 和 TabLayout 仍然可見?

[英]How to make Toolbar and TabLayout still visible even when CollapsingToolbarLayout is collapsed?

即使CollapsingToolbarLayout 折疊,如何使ToolbarTabLayout仍然可見?

For example, i have a CollapsingToolbarLayout with app:contentScrim animation that contains a Toolbar , ImageView and TabLayout but i want to hide the ImageView when scrolling, but still show the Toolbar and TabLayout inside the CollapsingToolbarLayout even when i swipe up and collapse the view.

我希望ToolbarTabLayout背景在展開CollapsingToolbarLayout時動畫成透明顏色,並且在折疊視圖時應該動畫成app:contentScrim指定的純色。

我正在嘗試在圖像中實現這一目標: 顯示的 CollapsingToolbarLayout 圖片來源: CollapsingToolBarLayout 與 TabLayout 和 ViewPager

我想我找到了解決方案:

<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/htab_maincontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/htab_appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/htab_collapse_toolbar"
        android:layout_width="match_parent"
        android:layout_height="256dp"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
        app:titleEnabled="false">

        <ImageView
            android:id="@+id/htab_header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/header"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0.3"
            android:background="@android:color/black"
            android:fitsSystemWindows="true"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/htab_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="top"
            android:layout_marginBottom="48dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/htab_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:tabIndicatorColor="@android:color/white"
            app:tabSelectedTextColor="@android:color/white"
            app:tabTextColor="@color/white_70"/>

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

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

<android.support.v4.view.ViewPager
    android:id="@+id/htab_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://blog.iamsuleiman.com/parallax-scrolling-tabs-design-support-library/comment-page-3/#comment-52129

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM