2013-10-08 80 views
0

我在查看如何讓動畫視圖消失?

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

} 
+0

@Kerry如果你要編輯我的文章 - 也許你可以回答我的問題? –

回答

0

當您在View mTarget上設置可見性後,嘗試在其上調用invalidate()。這假定你從主線程調用它,否則它是postinvalidate()。

+0

我希望它有幫助,但它仍然沒有消失:( –

+0

你能發佈你的完整代碼嗎? – Kerry

+0

我貼的代碼,是我的完整代碼短的 mTarget =(View)fragment.findViewById(R.id.target ) –