【问题标题】:How to make extended app bar with tabs collapse and expand while scrolling?如何使带有标签的扩展应用栏在滚动时折叠和展开?
【发布时间】:2016-06-06 23:09:14
【问题描述】:

这里是新手。我目前正在为我们在学校的项目开发一个应用程序,我们希望在扩展的应用程序栏上显示徽标,并且会在滚动时淡出并折叠,那么有什么方法可以做到吗?

我做的样机样机展示了我的意思: canteen_home.gif

【问题讨论】:

    标签: java android material-design toolbar appbar


    【解决方案1】:

    我终于得到了答案,它来自 Chris Banes 的 Cheesequare git,Paul 强调:https://gist.github.com/iPaulPro/1468510f046cb10c51ea

    还有我的编辑版本:

    <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"
    tools:context=".Home">
    
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        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/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <ImageView
                android:id="@+id/background"
                android:layout_width="match_parent"
                android:layout_height="256dp"
                android:scaleType="centerCrop"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                android:src="@drawable/hotdog"/>
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                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.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="bottom"
            android:background="?attr/colorPrimary"
            app:tabMode="scrollable"/>
    </android.support.design.widget.AppBarLayout>
    
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
    </android.support.design.widget.CoordinatorLayout>
    

    【讨论】:

      【解决方案2】:

      参考this。它准确地解释了如何实现你想要的。

      【讨论】:

        【解决方案3】:
        猜你喜欢
        • 2015-03-29
        • 1970-01-01
        • 1970-01-01
        • 2011-11-01
        • 2018-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-20
        相关资源
        最近更新 更多