利用GitHub开源组件PullToRefresh实现上拉下拉弹簧效果

实现原理:

将开源库中下拉刷新布局文件中的根节点FrameLayout visibility属性设置成GONE即可

在此方法中找到引用该布局的LoadingLayout文件,找到该FrameLayout,然后通过外部自定义标签动态设置其显隐状态

让我们以PullToRefreshScrollView为例,仅通过三步修改代码就实现上拉下拉的弹簧效果

第一步

打开res/vaules/attrs.xml,并在最后自定义如下属性:

<attr name="isElastic" format="reference|boolean" />

第二步

找到com.handmark.pulltorefresh.internal包下的LoadingLayout.java文件。

先声明一个布尔型的变量  private boolean IsElastic;

然后找到如下代码段

mInnerLayout = (FrameLayout) findViewById(R.id.fl_inner);
mHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_text);
mHeaderProgress = (ProgressBar) mInnerLayout.findViewById(R.id.pull_to_refresh_progress);
mSubHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_sub_text);
mHeaderImage = (ImageView) mInnerLayout.findViewById(R.id.pull_to_refresh_image);

在这后面加上下列代码

if (attrs.hasValue(R.styleable.PullToRefresh_isElastic)) {
IsElastic = attrs.getBoolean(R.styleable.PullToRefresh_isElastic, false);
}
if(IsElastic)
       mInnerLayout.setVisibility(View.GONE);

第三步

在调用PullToRefreshScrollView的布局文件里设置isElastic属性,类似下面:

<com.handmark.pulltorefresh.library.PullToRefreshScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/pull_refresh_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        ptr:ptrAnimationStyle="flip"
        ptr:ptrMode="both" 

        ptr:isElastic="true">

</com.handmark.pulltorefresh.library.PullToRefreshScrollView>


完毕!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值