下拉刷新动画不能关闭的BUG

最近项目中遇到一个下拉刷新动画不能关闭的bug,在连续点击强制手动刷新的时候,刷新动画一直存在不能关闭;下拉刷新则没有此问题。查阅代码发现是刷新控件的问题:

    //比较新旧滚动值
    if(oldScrollValue !=newScrollValue) {
       //滚动
        if (delayMillis > 0) {
            postDelayed(mCurrentSmoothScrollRunnable, delayMillis);
        } else {
            post(mCurrentSmoothScrollRunnable);
        }
    }

mCurrentSmoothScrollRunnable代码

final class SmoothScrollRunnable implements Runnable {
        private final Interpolator mInterpolator;
        private final int mScrollToY;
        private final int mScrollFromY;
        private final long mDuration;
        private OnSmoothScrollFinishedListener mListener;

        private boolean mContinueRunning = true;
        private long mStartTime = -1;
        private int mCurrentY = -1;

        public SmoothScrollRunnable(int fromY, int toY, long duration, OnSmoothScrollFinishedListener listener) {
            mScrollFromY = fromY;
            mScrollToY = toY;
            mInterpolator = mScrollAnimationInterpolator;
            mDuration = duration;
            mListener = listener;
        }

        @Override
        public void run() {
            if (mStartTime == -1) {
                mStartTime = System.currentTimeMillis();
            } else {
                ......
                mCurrentY = mScrollFromY - deltaY;
                setHeaderScroll(mCurrentY);
            }
            // If we're not at the target Y, keep going...
            if (mContinueRunning && mScrollToY != mCurrentY) {
                ViewCompat.postOnAnimation(PullToRefreshBase.this, this);
            }  
            //mScrollToY == mCurrentY滚动到指定位置,下拉界面完全展开,调用滚动结束监听
            else {
                if (null != mListener) {
                    mListener.onSmoothScrollFinished();
                }
            }
        }

原因:实现机制滚动到指定位置,下拉界面完全展开,调用滚动结束监听。如果正好下拉界面完全展开的时候点击了强制刷新,则不会调用滚动结束监听

解决方案:

    if(oldScrollValue !=newScrollValue) {
       //滚动
        if (delayMillis > 0) {
            postDelayed(mCurrentSmoothScrollRunnable, delayMillis);
        } else {
            post(mCurrentSmoothScrollRunnable);
        }
    }
    //增加以下代码解决手动刷新问题
    else{
        if (null != listener) {
            listener.onSmoothScrollFinished();
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值