【问题标题】:Android - Fading Toolbar On Scroll ChangesAndroid - 滚动更改时淡出工具栏
【发布时间】:2016-12-11 20:08:51
【问题描述】:

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

我知道第三方库,例如:

Manuel Peinado's Fading Action Bar

ObservableScrollView

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

来自本教程: http://cyrilmottier.com/2013/05/24/pushing-the-actionbar-to-the-next-level/ 我发现我怎样才能为 Action Bar 实现这个效果,但是工具栏呢?

【问题讨论】:

  • 您的第一个库 github.com/ManuelPeinado/FadingActionBar 基于 Cyril Mottier 的教程。所以这几乎是一样的东西。 CyrillMottier 编写了 OnScrollChangedListener 类,您可以将其附加到工具栏。你应该考虑一下。

标签: android scroll android-actionbar toolbar


【解决方案1】:
<?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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-17
    • 1970-01-01
    • 2016-06-03
    • 2016-01-26
    • 1970-01-01
    相关资源
    最近更新 更多