Android - 滚动更改时的淡出工具栏

时间:2015-11-11 14:05:16

标签: android scroll android-actionbar toolbar

问题很简单,我想在滚动更改时淡出/淡出工具栏(如Google Play应用程序)

我了解第三方图书馆,如:

Manuel Peinado's Fading Action Bar

ObservableScrollView

但我不想使用它们,我想学习如何实现这种效果

本教程中的

http://cyrilmottier.com/2013/05/24/pushing-the-actionbar-to-the-next-level/ 我发现如何为Action Bar实现此效果,但工具栏呢?

1 个答案:

答案 0 :(得分:0)

<?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"
    xmlns:custom="http://schemas.android.com/tools"
    android:id="@+id/main_content"
    android:layoutDirection="ltr"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="450dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:background="@color/colorPrimary"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:gravity="right"
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorPrimary"
            app:expandedTitleMarginStart="10dp"
            app:expandedTitleMarginEnd="10dp">
<!--your image or slider-->
            <com.daimajia.slider.library.SliderLayout
                android:background="#ffffff"
                android:id="@+id/slider"
                android:layout_width="match_parent"
                custom:pager_animation="Accordion"
                custom:indicator_visibility="visible"
                android:fitsSystemWindows="true"
                android:gravity="center"

                custom:pager_animation_span="500"
                android:layout_height="match_parent"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:elevation="8dp"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />

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

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#cccccc"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="0dp"
            android:orientation="vertical">

          <!--your desighn-->
        </LinearLayout>

    </android.support.v4.widget.NestedScrollView>

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