未设置ValueAnimator持续时间

时间:2015-08-18 16:39:23

标签: java android animation

我正在尝试从this iOS-like Bounce Effect重现this library

当我从触摸RelativeLayout时释放时,它会立即返回到顶部,当它应该以{{1​​}}毫秒的持续时间反弹时。

弹跳动画类

n

这是我们应该能够改变动画持续时间的地方:

public class Bouncer implements AnimatorUpdateListener, AnimatorListener {

        private ValueAnimator mAnimator;
        private int mLastOffset;
        private boolean isHeader;
        private State mTargetState;
        private boolean mCanceled;

        public void recover(boolean header, int offset, State state) {
            cancel();
            Log.d(TAG, "recover offset " + offset);
            mCanceled = false;
            isHeader = header;
            mTargetState = state;
            mAnimator = new ValueAnimator();
            mAnimator.setIntValues(0, offset);
            mLastOffset = 0;
            mAnimator.setRepeatCount(0);
            if (mInterpolator == null) {
                mInterpolator = new DecelerateInterpolator();
            }
            mAnimator.setInterpolator(mInterpolator);
            mAnimator.addListener(this);
            mAnimator.addUpdateListener(this);
            mAnimator.setDuration((long) 1000).start();
        }

        public void cancel() {
            if (mAnimator != null && mAnimator.isRunning()) {
                mAnimator.cancel();
            }
            mAnimator = null;
        }

        @Override
        public void onAnimationUpdate(ValueAnimator va) {
            int currentOffset = (Integer) va.getAnimatedValue();
            int delta = mLastOffset - currentOffset;
            Log.d(TAG, "recover delta " + delta + " currentOffset "
                    + currentOffset);
            offsetContent(delta);
            mLastOffset = currentOffset;

            if (mListener != null) {
                int contentOffset = mContentView.getTop();
                mListener.onOffset(isHeader, contentOffset);
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            Log.d(TAG, "onAnimationEnd");
            mAnimator = null;
            if (!mCanceled) {
                setState(isHeader, mTargetState);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            Log.d(TAG, "onAnimationCancel");
            mCanceled = true;
        }
    }

但这条线根本没有任何区别。

任何想法为什么?

1 个答案:

答案 0 :(得分:0)

回到图书馆的original commited课程已经解决了我的问题。

以前这是一个有效的Canvas动画,我不知道为什么他们已将其更改为ValueAnimator