2011-10-03 90 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。将起作用;)