首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何避免在旋转动画后保存图像时出现闪烁图像?

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

Stack Overflow用户
提问于 2011-10-03 11:37:00
回答 1查看 753关注 0票数 4

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

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

谢谢。

代码语言:javascript
运行
复制
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);
                }
        });
EN

回答 1

Stack Overflow用户

发布于 2014-11-14 00:38:56

我曾经遇到过这个问题,但它真的很容易解决。你不需要实现动画监听器,简单的说就是不要这样做(我遇到了你的问题,因为我是这样使用的)。

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

如下所示:

代码语言:javascript
运行
复制
//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。Will工作;)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7630825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档