CoordinatorLayout+AppBarLayout隐藏标题栏

本文介绍了如何在Android应用中利用CoordinatorLayout和AppBarLayout实现标题栏隐藏的效果。通过设置特定的layout_scrollFlags和layout_behavior属性,可以实现在滚动时标题栏的动态显示和隐藏。主要涉及的属性包括:scroll、enterAlways、enterAlwaysCollapsed和exitUntilCollapsed。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先上代码

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

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent">

app:layout_scrollFlags="scroll|enterAlways"

android:fitsSystemWindows="true"

android:layout_width="match_parent"

android:layout_height="wrap_content">

app:layout_scrollFlags="scroll|enterAlways"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:layout_centerInParent="true"

android:text="我是要隐藏的顶部标题"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

app:layout_behavior="@string/appbar_scrolling_view_behavior"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:text="标题"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

app:layout_behavior="@string/appbar_scrolling_view_behavior"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical">

android:text="我是中间的布局"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

android:paddingTop="100dp"

android:id="@+id/recycle"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

哪个控件要隐藏就设置app:layout_scrollFlags="scroll|enterAlways"

哪个控件滑动设置  app:layout_behavior="@string/appbar_scrolling_view_behavior"(通知布局中包含滑动组件!)


scroll: 所有想滚动出屏幕的view都需要设置这个flag- 没有设置这个flag的view将被固定在屏幕顶部。

enterAlways:这个flag让任意向下的滚动都会导致该view变为可见,启用快速“返回模式”。

enterAlwaysCollapsed:当你的视图已经设置minHeight属性又使用此标志时,你的视图只能已最小高度进入,只有当滚动视图到达顶部时才扩大到完整高度。

exitUntilCollapsed: 滚动退出屏幕,最后折叠在顶端。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值