android内容页折叠,android – 如何折叠AppBarLayout但不是工具栏的内容

本文介绍如何使用CoordinatorLayout实现标题在滚动时自动折叠,配合AppBarLayout和CollapsingToolbarLayout,提供了一个Android开发中常见布局的实践案例。

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

如果我理解正确,你想在滚动时折叠标题的一部分.如果是这样的话,@ Nerd的评论链接到一个关于如何做到这一点的好教程.无论如何,我将在这里留下一个CoordinatorLayout用法示例,它可以满足您的需求:

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

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fitsSystemWindows="true">

android:id="@+id/app_bar_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:fitsSystemWindows="true"

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

android:id="@+id/collapsing_toolbar"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:fitsSystemWindows="true"

app:contentScrim="?attr/colorPrimary"

app:expandedTitleMarginEnd="64dp"

app:expandedTitleMarginStart="48dp"

app:layout_scrollFlags="scroll|exitUntilCollapsed">

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

app:layout_collapseMode="pin"

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

android:id="@+id/scroll"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:clipToPadding="false"

app:layout_behavior="@string/appbar_scrolling_view_behavior">

android:id="@+id/fab"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="16dp"

android:clickable="true"

app:layout_anchor="@id/app_bar_layout"

app:layout_anchorGravity="bottom|right|end"/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值