您的位置:首页 > 其它

安卓开发中实现页面越界回弹和上下拉的刷新自定义动画的操作(TwinklingRefreshLayout布局的使用)

2017-10-25 17:13 901 查看
概述

TwinklingRefreshLayout实现越界回弹的写法

TwinklingRefreshLayout上拉加载更多下拉刷新的自定义属性

自定义的PullToRefresh实现的越界回弹和刷新操作

概述:

安卓原生页面经常会有类似iOS那种越界回弹的效果,感觉看起来比价灵动,不是说一定要跟着iOS走,只是为了实现更好的效果,TwinklingRefreshLayout这是个布局文件,本质就是RelativeLayout,他可以实现类似PullToRefush那种上拉和下拉的加载动画,也可以实现纯净的越界回弹效果,不带任何动画,并且兼容RecycleView,listview等滑动布局,不用费力去处理ScrollView嵌套RecycleView等出现的滑动冲突,导致页面卡顿,itemview不能复用等一系列问题。

TwinklingRefreshLayout实现越界回弹的写法

1、buildgrade中添加依赖:

compile 'com.lcodecorex:tkrefreshlayout:1.0.7'


xml布局文件(这里就是嵌套RecycleView并且要分页加载的)

<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tr_pureScrollMode_on="true"
android:background="@color/shopbg">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycleview"

4000
android:layout_width="match_parent"
android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>


2、这样就实现了纯净的越界回弹效果,上边的app:tr_pureScrollMode_on=”true”属性就是不添加任何动画的越界回弹,不添加此属性就是类似PullToRefresh那种下拉刷新上拉加载更多 的效果,但是动画样式可以自定义

TwinklingRefreshLayout上拉加载更多,下拉刷新的自定义属性

网上详细的说明:http://blog.csdn.net/u014608640/article/details/52933584

http://www.jianshu.com/p/5ed4813b86cf这两个已经很详细了,也可以在GitHub上查看作者的说明:https://github.com/lcodecorex/TwinklingRefreshLayout都是中文说明

自定义的PullToRefresh实现的越界回弹和刷新操作

其实就是重写一个PullToRefresh的一个三方库,attr文件中添加isElastic属性,为true时候就是越界回弹,不设置默认就是刷新和加载更多的操作,当然也可以修改动画

<com.handmark.pulltorefresh.library.PullToRefreshScrollView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_light"
ptr:ptrMode="both"
ptr:isElastic="true">
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐