一步步走进Android MaterialDesign 之 ToolBar动画效果(2)

今天就学一个控件CollapsingToolbarLayout

依然看效果图
这里写图片描述

这效果看上去还是有点帅的吧,实现起来也是很简单的,我们仅仅在上一篇代码基础上进行修改,修改AppBarLayout部分

<android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="400dp">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsingtoolbarlayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:src="@mipmap/detail_pic"
                app:layout_collapseMode="parallax"/>
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?actionBarSize"
                app:layout_collapseMode="pin">

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

依然讲解重点部分

  • CollapsingToolbarLayout 其实我不知道应该怎么描述比较合适,从表面看这玩意就是把Toolbar包裹在里面做个折叠动画

  • app:contentScrim 这个就是折叠后ToolBar的背景,我们这里要是不设置的话,就会把ImageView取最后一部分作为背景

  • app:layout_scrollFlags 这个没什么好说的,就是滚滚滚。exitUntilCollapsed就是向下滚动的时候也不会滚出来,除非自己一直在向下滚

  • app:layout_collapseMode 这个是比较重要的地方,当属性是pin的时候,在折叠后他就固定在顶部,一般情况下它是处于被放大的状态;parallax的时候,就会由一个差值因子来造成滚动差

  • 请注意这边不是用ToolBar来设置标题的,而是CollapsingToolbarLayout

collapsingtoolbarlayout= (CollapsingToolbarLayout) findViewById(R.id.collapsingtoolbarlayout);
collapsingtoolbarlayout.setTitle("NestedScrollView");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值