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

发布于 2024-12-08 09:27:04 字数 2392 浏览 4 评论 0原文

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

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

谢谢。

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

I am confusing the translate animation and rotate animation. In my game I use this two animations, after completing the animation I am save my image. In translate animation it is fine, but after completing rotate animation my image is blink once. See my code in bellow, please solve my problem……..

Why anyone not respond my question, it is not understand or I am asking any wrong question ? Please tell me reason.................

Thanks.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌伤ぢ 2024-12-15 09:27:04

我遇到了这个问题,但解决起来非常简单。您不需要实现动画侦听器,简单地不要这样做(我遇到了您的问题,因为我使用这种方式)。

执行动画并在调用动画方法之前:
setFillAfter(真); //这个在动画结束时保存视图

像这样:

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

i had that problem but it's reaaaaally simple to fix. You don't need to implement the animation listener, simple don't do it (i had your problem because I use that way).

Do your animation and before call the animation method:
setFillAfter(true); //this save view at the end of the animation

Like so:

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

So, delete the listeners and change your setFillAfter(false) to TRUE. Will works ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文