android 滑动固定标题,Android 使用CoordinatorLayout实现滚动标题栏效果的实例

本文介绍了如何在Android中使用CoordinatorLayout配合AppBarLayout和CollapsingToolbarLayout实现滑动固定标题的效果。通过设置布局参数如app:layout_scrollFlags和app:layout_collapseMode,可以创建出滚动时标题栏动态变化的UI交互。
摘要由CSDN通过智能技术生成

在Material Design里,CoordinatorLayout通常用来作为顶层视图,来协调处理各个子View之间的动作,从而实现各种动画效果,如Snackbar与FloatingActionButton的配合显示效果,就是以CoordinatorLayout作为根布局来实现的

CoordinatorLayout提供Behaviors接口,子View通过实现Behaviors接口来协调和其它View之间的显示效果,可以这么理解:

CoordinatorLayout让其子View之间互相知道彼此的存在,任意一个子View的状态变化会通过Behaviors通知其它子View,CoordinatorLayout就像一个桥梁,连接不同的View,并使用Behavior处理各个子View之间的通信

效果一:

a315acab79457975ba9877918f6cac1d.gif

想实现这样的效果挺简单的,主要是在xml布局文件中进行设置

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

android:layout_width="match_parent"

android:layout_height="match_parent"

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

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:theme="@style/ThemeOverlay.AppCompat">

android:id="@+id/tb_toolbar"

android:layout_width="match_parent"

android:layout_height&

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值