2011-10-03 92 views
4

我很困惑翻譯動畫和旋轉動畫。在我的遊戲中,我使用這兩個動畫,完成動畫後,我保存了我的圖像。在翻譯動畫中很好,但是在完成旋轉動畫後,我的圖像會閃爍一次。看到我的代碼在波紋管中,請解決我的問題...... ..如何在旋轉動畫後保存圖像時避免閃爍圖像?

爲什麼有人不迴應我的問題,它不明白,或者我問任何錯誤的問題?請告訴我理由.................

謝謝。

Bitmap bmp=BitmapFactory.decodeResource(getResources(),R.drawable.train); 
//1) 
TranslateAnimation TAnimation=new TranslateAnimation(0, 0, 0,-100);//bottom to start 
     TAnimation.setInterpolator(new LinearInterpolator()); 
     TAnimation.setDuration(2000); 
     TAnimation.setFillAfter(false); 
     TAnimation.setFillEnabled(true); 
     //TAnimation.setFillBefore(true); 
     Train.startAnimation(TAnimation); 

TAnimation.setAnimationListener(new AnimationListener() { 

      public void onAnimationStart(Animation animation) { 

      } 

      public void onAnimationRepeat(Animation animation) { 

      } 

      public void onAnimationEnd(Animation animation) { 

       RelativeLayout RL=(RelativeLayout)findViewById(R.id.rl); 
        param=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 
       param.setMargins(x, y, 0, 0); 
        Train.setLayoutParams(param); 
        Train.setImageBitmap(bmp);  
      } 
     }); 
    //x and y values are exact position of compliting translateanimation position 
//2) 
RotateAnimation RAnimation=new RotateAnimation(0,90,50,25); 
     RAnimation.setInterpolator(new LinearInterpolator()); 
     RAnimation.setDuration(2000); 
     RAnimation.setFillAfter(false); 
     TAnimation.setFillEnabled(true); 
     //RAnimation.setFillBefore(true); 
     Train.startAnimation(RAnimation); 
RAnimation.setAnimationListener(new AnimationListener() { 

      public void onAnimationStart(Animation animation) { 

      } 

      public void onAnimationRepeat(Animation animation) { 

      } 
      public void onAnimationEnd(Animation animation) { 
       RelativeLayout RL=(RelativeLayout)findViewById(R.id.rl); 
        param=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 
       param.setMargins(x, y, 0, 0);//x and y values are exact position of compliting translateanimation position 
        Train.setLayoutParams(param); 
        Train.setImageBitmap(bmp); 
       } 
     }); 

回答

1

我有這個問題,但它修復起來非常簡單。你不需要實現動畫監聽器,簡單不要做(我有你的問題,因爲我用這種方式)。

做你的動畫,然後調用動畫方法: setFillAfter(true); //這在動畫

結束時,保存視圖,像這樣:

//my animation 
final Animation rotation = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_up); 
//hide login content 
content.setVisibility(View.GONE); 
//animContent = AnimationUtils.loadAnimation(getActivity(), R.anim.show_up); 
rotation.setFillAfter(true); 
//animate the arrow 
arrow.startAnimation(rotation); 

因此,刪除聽衆和改變你的setFillAfter(假)爲TRUE。將起作用;)