如何让动画视图消失?

时间:2013-10-08 15:14:30

标签: android animation

我在视图

上使用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();

}

1 个答案:

答案 0 :(得分:0)

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