AppBarLayout.OnOffsetChangedListener的使用
2016-03-23 21:15
369 查看
先看看官网对于AppBarLayout.OnOffsetChangedListener的解释:
Interface definition for a callback to be invoked when an AppBarLayout's
vertical offset changes.
当AppBarLayout垂直方向上的偏移量发生改变时,为触发一个回调方法定义的接口。
触发的回调方法是:
onOffsetChanged(AppBarLayout appBarLayout,
int verticalOffset)
再来看看对于onOffsetChanged的解释:
Called when the AppBarLayout's
layout offset has been changed. This allows child views to implement custom behavior based on the offset (for instance pinning a view at a certain y value).
在AppBarLayout的布局偏移量发生改变时被调用。这个方法允许子view根据偏移量实现自定义的行为(比如在特定Y值的时候固定住一个View)。
解释的非常清楚了,不过我们需要点例子才好理解。
就以stackoverflow上的一个问题为例吧。
http://stackoverflow.com/questions/30779667/android-collapsingtoolbarlayout-and-swiperefreshlayout/30785823#30785823
当我把CollapsingToolbarLayout,CollapsingToolbarLayout以及SwipeRefreshLayout用在一起的时候:
java代码:
如何才能让滑动刷新只发生在collapsing toolbar完全展开并且 scrollview (或者recyclerview)在顶部 的时候呢?类似于g+和Inbox中的效果。
错误的效果:
正确的效果:
可以尝试为AppBarLayout添加 offset change listener同时根据情况启用或者关闭滑动刷新,需要增加的代码在这里:
https://gist.github.com/blackcj/001a90c7775765ad5212
关键改动:
点击打开链接
Interface definition for a callback to be invoked when an AppBarLayout's
vertical offset changes.
当AppBarLayout垂直方向上的偏移量发生改变时,为触发一个回调方法定义的接口。
触发的回调方法是:
onOffsetChanged(AppBarLayout appBarLayout,
int verticalOffset)
再来看看对于onOffsetChanged的解释:
Called when the AppBarLayout's
layout offset has been changed. This allows child views to implement custom behavior based on the offset (for instance pinning a view at a certain y value).
在AppBarLayout的布局偏移量发生改变时被调用。这个方法允许子view根据偏移量实现自定义的行为(比如在特定Y值的时候固定住一个View)。
解释的非常清楚了,不过我们需要点例子才好理解。
就以stackoverflow上的一个问题为例吧。
http://stackoverflow.com/questions/30779667/android-collapsingtoolbarlayout-and-swiperefreshlayout/30785823#30785823
问题描述
当我把CollapsingToolbarLayout,CollapsingToolbarLayout以及SwipeRefreshLayout用在一起的时候:错误的效果:
正确的效果:
回答:
可以尝试为AppBarLayout添加 offset change listener同时根据情况启用或者关闭滑动刷新,需要增加的代码在这里:https://gist.github.com/blackcj/001a90c7775765ad5212
关键改动:
相关文章推荐
- IOS开发-OC学习-Foundation框架练习
- Android TabLayout、ViewPager实现顶部和底部Tab导航 点击滑动切换Tab页面
- IOS开发-ObjC-NSDictionary
- Android之ListView使用总结
- iOS 8 Auto Layout界面自动布局系列3-使用代码添加布局约束
- 理解Android系统的四大组件
- iOS-NSDateFormatter 格式说明
- IOS开发-ObjC-NSArray
- IOS-通讯录
- Android框架设计模式(三)——Observer Method
- Error running app:Instant Run requires 'Tools|Android|Enable ADB integration' to be enable
- iOSDay13之OC NSString类
- [android] 隐式意图激活另外一个activity
- Android Studio SVN的使用
- iOS -- pch文件介绍 及用法 - $(SRCROOT)/工程名/pch文件名.pch -- <一>
- iOS开发~CocoaPods使用详细说明
- iOS调试奇巧淫技(一)
- appium+python解锁应用手势密码
- Android中的5中数据存储方式之SharedPreferences存储
- Unity基础知识总结