0

我在 View 上使用NineOldAndroid的 AnimatorSet

当我想摆脱动画并让视图消失时 - 什么也没有发生

我如何让视图消失?

    public void showAnimation(boolean show) {
    if (show) {
        if (mTarget.getVisibility() != View.VISIBLE) {
            // play sound

            mTarget.setVisibility(View.VISIBLE);
            pauseAnimation = false;
            // start animation
            initTargetAnimation();
        }
    } else {

        pauseAnimation = true;    //All of this block gets executed in the debugger, but none of it actually take effect
        if (mTarget.getAnimation() != null) {
            mTarget.getAnimation().cancel();
            mTarget.clearAnimation();
        }
        mTarget.setVisibility(View.GONE);
    }



}

    private void initTargetAnimation() {

    final AnimatorSet set = new AnimatorSet();

    // init animation properties
    set.playTogether(ObjectAnimator.ofFloat(mTarget, "scaleX", RELEVANT_ANIMATION_SEQUENCE), ObjectAnimator.ofFloat(mTarget, "scaleY", RELEVANT_ANIMATION_SEQUENCE));

    // add animation listener
    set.setDuration(1500).addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // RESTART ANIMATION
            if (!pauseAnimation) {
                initTargetAnimation(); // TODO fix
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

    // start animation
    set.start();

}
4

1 回答 1

0

在 View mTarget 上设置可见性后,尝试在其上调用 invalidate()。这假设您从主线程调用它,否则它是 postinvalidate()。

于 2013-10-08T16:29:49.507 回答