动画徽标以及CoordinatorLayout中的折叠工具栏

时间:2015-06-26 12:54:09

标签: android android-design-library android-coordinatorlayout

我想以下列方式实现带有徽标的可折叠工具栏:

  1. 内容重叠的灵活空间,如shown here(已有此内容);
  2. 此空间中的视差图案以纯色为蓝色(也有这个)
  3. 水平居中的徽标,必须出现在内容正上方,但在工具栏崩溃时向上浮动: mockup 在行动中它应该像Pesto的叶子一样(不一定可以调整大小,但这将是一个加号): in motion
  4. 这是我的布局:

    <android.support.design.widget.CoordinatorLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            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="192dp"
                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="match_parent"
                    android:fitsSystemWindows="true"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed"
                    app:contentScrim="?attr/colorPrimary">
    
                <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:fitsSystemWindows="true"
                        android:src="@drawable/random_pattern"
                        android:scaleType="fitXY"
                        app:layout_collapseMode="parallax"
                        app:layout_collapseParallaxMultiplier="0.75"/>
    
                <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.v7.widget.Toolbar>
    
            </android.support.design.widget.CollapsingToolbarLayout>
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v4.widget.NestedScrollView
                android:id="@+id/nested_scroll_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                app:behavior_overlapTop="64dp">
    
            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    tools:context=".MainActivityFragment"
                    android:orientation="vertical">
    
                <android.support.v7.widget.CardView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="8dp">
    
                    <!-- card content -->
    
                </android.support.v7.widget.CardView>
    
            </LinearLayout>
    
        </android.support.v4.widget.NestedScrollView>
    
    </android.support.design.widget.CoordinatorLayout>
    

    问题是,无论我在哪里放置徽标图片,要么它不像我需要的那样移动,要么一切都坏了。感觉可能需要自定义行为。不幸的是,我在新设计库中找到的教程 都没有解释如何扩展它 - 只讨论如何使用提供的东西。它没有发布的源代码,反编译的代码没有评论,而且非常纠结,而且我对Android的布局内部结构不太满意这一事实使它更糟糕。

    请帮帮忙?

1 个答案:

答案 0 :(得分:8)

好的,我确实做到了!

我的解决方案非常糟糕,所以我仍然期待更好的解决方案:)

我继续创建了一个自定义视图CollapsingLogoToolbarLayout,它是CollapsingToolbarLayout的子类。后一类是标题转换的处理方式 - 所以在我的子类中,我放置了改变徽标视图属性的逻辑,即基于&#34;扩展的&#34;分数。 Gist with code is here。现在,在找到合适的偏移参数后,我的布局如下所示:

translationY

Recording

相关问题