android - 如何像 Google Play press 一样实现标题

标签 android android-support-library material-design

如何像 Google Play press 一样实现页眉? 如何在背景中实现随内容滚动的动画图像? Google Play 新闻屏幕 1:full header Google Play 新闻屏幕 2:minimized header

我的代码:

<android.support.v4.widget.DrawerLayout 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:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.inthecheesefactory.lab.designlibrary.activity.CodeLabActivity">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/rootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal|center_vertical"
                android:background="#123456"
                android:scaleType="centerCrop"
                android:src="@drawable/nav_header_bg"
                app:layout_collapseMode="parallax" />
        </android.support.design.widget.CollapsingToolbarLayout>

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingToolbarLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#234123"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/transparent"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabLayout"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/transparent"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:tabContentStart="0dp"
                app:tabMode="scrollable"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

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

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


    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScrollViewContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="800dp"
            android:orientation="vertical">

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/nav_header"
    app:itemIconTint="@color/nav_item_icon_tint_color"
    app:itemTextColor="@color/nav_item_text_color"
    app:menu="@menu/navigation_drawer_items" />

最佳答案

尝试使用库 https://github.com/florent37/MaterialViewPager/

这是你需要的:

enter image description here

关于android - 如何像 Google Play press 一样实现标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31678907/

相关文章:

java - 任务 :app:compileDebugJavaWithJavac in Android Studio 执行失败

当我反向运行动画时,Android 会跳过 onDraw()

android - 检测用户是否丢弃消息

android - CoordinatorLayout、FAB和容器布局冲突

android - 在 Android Studio 中使用 Material Design 组件

android - phonegap adb 中的 INSTALL_FAILED_OLDER_SDK

android - 以编程方式更改 Android CheckBox 框的颜色(支持库)?

java - 为什么我不能强制 EditTextPreference 只取数字?

android - CardView 位于 FrameLayout 之上,但首先声明

android MaterialDialog 未关闭