android折叠标题栏带动画,084-可折叠式标题栏-CollapsingToolbarLayout

虽说我们现在的标题栏是使用Toolbar来编写的, 不过它看上去和传统的ActionBar其实没什么两样, 只不过可以响应RecyclerView的滚动事件来进行隐藏和显示。 而Material Design中并没有限定标题栏必须是长这个样子的, 事实上, 我们可以根据自己的喜好随意定制标题栏的样式。

顾名思义, CollapsingToolbarLayout是一个作用于Toolbar基础之上的布局, 它也是由DesignSupport库提供的。 CollapsingToolbarLayout可以让Toolbar的效果变得更加丰富, 不仅仅是展示一个标题栏, 而是能够实现非常华丽的效果。

不过, CollapsingToolbarLayout是不能独立存在的, 它在设计的时候就被限定只能作为

AppBarLayout的直接子布局来使用。 而AppBarLayout又必须是CoordinatorLayout的子布局, 因此

本节中我们要实现的功能其实需要综合运用前面所学的各种知识。

首先我们需要一个额外的活动来作为水果的详情展示界面,右击com.example.materialtest包

→New→Activity→Empty Activity, 创建一个FruitActivity, 并将布局名指定成activity_fruit.xml,

然后我们开始编写水果详情展示界面的布局。

由于整个布局文件比较复杂, 这里我准备采用分段编写的方式。 activity_fruit.xml中的内容主要分为两部分, 一个是水果标题栏, 一个是水果内容详情, 我们来一步步实现。

接下来, 我们在CollapsingToolbarLayout中定义标题栏的具体内容, 如下所示:

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/appBar"

android:layout_width="match_parent"

android:layout_height="250dp">

android:id="@+id/collapsing_toolbar"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

app:contentScrim="?attr/colorPrimary"

app:layout_scrollFlags="scroll|exitUntilCollapsed">

android:id="@+id/fruit_imag

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值