【问题标题】:Content slide on app bar应用栏上的内容幻灯片
【发布时间】:2018-06-03 09:51:06
【问题描述】:

在我的 android 应用程序中,我希望工具栏保持固定并且活动的内容滑过它,我怎样才能实现这种效果?

【问题讨论】:

  • 效果与使用新的背景设计组件相同(如 MDC 代码实验室中的示例应用 Shrine)。

标签: android android-layout android-actionbar


【解决方案1】:

所以,只需创建名为 your_activity_name 的布局并通过此代码

  <?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:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        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="wrap_content"
            app:contentScrim="?colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:fitsSystemWindows="true"
                />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                />

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

    //your main content here

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

欲了解更多信息,请查看此链接http://saulmm.github.io/mastering-coordinator

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 2013-06-06
    • 2011-08-22
    • 2013-10-14
    • 1970-01-01
    • 2014-01-25
    相关资源
    最近更新 更多