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

标签 android android-animation

我混淆了平移动画和旋转动画。在我的游戏中我使用这两个动画,完成动画后我保存我的图像。在翻译动画中它很好,但在完成旋转动画后我的图像闪烁一次。看下面我的代码,请解决我的问题……..

为什么没有人回答我的问题,不明白或者我问错了问题?请告诉我原因......................

谢谢。

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

最佳答案

我遇到了这个问题,但修复起来非常简单。你不需要实现动画监听器,简单的不要这样做(我有你的问题,因为我使用那种方式)。

做你的动画,然后调用动画方法: 设置填充后(真);//在动画结束时保存 View

像这样:

//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。将工作;)

关于android - 旋转动画后保存图像时如何避免闪烁图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7630825/

相关文章:

android - Kotlin: "return@"是什么意思?

java - ANDROID 使用分享 Intent 分享到 Facebook、Twitter 等

带有 OnClickListener 的 Android 警报对话框 - 语法错误

android - fragment 向上滑动动画不显示下方的 fragment

android - 键盘打开时如何使android edittext字段可见?

android - android 启动时,启动 Logo 后光标闪烁文本 "A N D R O I D _"

Android:带有持续可见滚动条的Fingerpaint

Android使用HTTP多部分表单数据上传视频到远程服务器

android - 如果提供横向模式的替代布局,则纵向模式的共享动画不会动画。 (适用于 android 支持库 23.0.0)

java - Android 致命信号 11 (SIGSEGV),代码 1,tid 29092 中的故障地址 0x0