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

概述:

安卓原生页面经常会有类似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"
                    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">
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值