android 二级列表悬停,Android案例分享系列--悬停列表

关键:协调布局CoordinatorLayout

方法:app:layout_behavior,指定子视图相对于其他视图的行为,当对方的位置发生变化时,本视图的位置也要随之变化

应用栏布局AppBarLayout,继承LinearLayout,可将AppBarLayout称作为头部

功能:1、支持响应页面主体的滑动行为,即页面在上移或者下移时,AppBarLayout能够捕捉到页面主体的滚动操作

2、捕捉到滚动操作之后,通知下级节点你要怎么滚

如app:layout_behavior="@string/appbar_scrolling_view_behavior" 表示通知AppBarLayout捕捉RecycleView的滚动操作

应用场景1:

app:layout_scrollFlags="scroll|exitUntilCollapsed">

app:layout_behavior="@string/appbar_scrolling_view_behavior">

应用场景2:

RecyclerView添头部有问题或者添头部不满足需要,就可以考虑用 CoordinatorLayout , AppBarLayout 和 CollapsingToolbarLayout组合解决问题

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/abl_city"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_scrollFlags="scroll|exitUntilCollapsed">

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_collapseMode="pin"

/>

android:id="@+id/rv_city"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/white"

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

属性介绍

顶部标题栏中定义的app:layout_scrollFlags属性:

此属性里面必须至少启用scroll这个flag,这样这个View才会滚动出屏幕,否则它将一直固定在顶部。

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

enterAlways:当滑动组件向下滚动时,标题栏会直接往下滚动。

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

exitUntilCollapsed:当标题栏要往上逐渐“消逝”时,会一直往上滑动,直到剩下的的高度达到它的最小高度,再响应滑动组件的内部滑动事件。

滑动列表中定义的app:layout_behavior属性:

滑动的组件必须要设置此属性,与AppBarLayout配合使用AppBarLayout才会响应滚动事件

AppBarLayout就是标题栏

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值