Android 旋转动画后保存图像时如何避免图像闪烁?

Android 旋转动画后保存图像时如何避免图像闪烁?,android,android-animation,Android,Android Animation,我混淆了平移动画和旋转动画。在我的游戏中,我使用这两个动画,完成动画后,我保存我的图像。在“平移动画”中可以,但在完成“旋转动画”后,我的图像会闪烁一次。请参阅下面的代码,请解决我的问题 为什么有人不回答我的问题,这是不理解或我问了任何错误的问题?请告诉我原因 谢谢 Bitmap bmp=BitmapFactory.decodeResource(getResources(),R.drawable.train); //1) TranslateAnimation TAnimation=new Tr

我混淆了平移动画和旋转动画。在我的游戏中,我使用这两个动画,完成动画后,我保存我的图像。在“平移动画”中可以,但在完成“旋转动画”后,我的图像会闪烁一次。请参阅下面的代码,请解决我的问题

为什么有人不回答我的问题,这是不理解或我问了任何错误的问题?请告诉我原因

谢谢

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);
                }
        });

我有这个问题,但修复起来真的很简单。你不需要实现动画监听器,简单地说,不要这样做(我有你的问题,因为我用那种方式)

执行动画,然后在调用动画方法之前: 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(false)更改为TRUE。遗嘱有效;)