nuptboyzhb / SuperSwipeRefreshLayout

A custom SwipeRefreshLayout to support the pull-to-refresh featrue.RecyclerView,ListView,GridView,NestedScrollView,ScrollView are supported.
Apache License 2.0
1.24k stars 350 forks source link

关于源码里面使用属性动画实现回滚 #10

Open TellH opened 8 years ago

TellH commented 8 years ago

我本来想重构一下代码,在mTarget和mHeaderViewContainer使用属性动画,让两者在手指松开时同时回滚到顶部,但这样做并不行,请问这是为什么?

ashqal commented 8 years ago
private Animation.AnimationListener mRefreshListener = new Animation.AnimationListener() {
   ...

    @Override
    public void onAnimationEnd(Animation animation) {
        isProgressEnable = true;
        if (mRefreshing) {
            ...
        } else {
            mHeadViewContainer.setVisibility(View.GONE);
            if (mScale) {
                setAnimationProgress(0);
            } else {
                /*
                setTargetOffsetTopAndBottom(mOriginalOffsetTop
                        - mCurrentTargetOffsetTop, true);
                        */
                final int from = mTarget.getTop();
                final int to = 0;
                ValueAnimator animator = ValueAnimator.ofFloat(0,1).setDuration(200);
                animator.addUpdateListener(new AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        float value = (float) animation.getAnimatedValue();
                        float step = (to - from) * value + from;
                        int top =  mTarget.getTop();
                        setTargetOffsetTopAndBottom((int) (step - top),true);
                    }
                });
                animator.start();
            }
        }
        ....
    }
};

这样应该就可以了