Android 动画无法正常工作
我使用以下代码段来制作气球动画。这里的气球什么也不是,只有按钮,并且它使用平移动画来制作动画。
动画效果很好,但是当气球移动时会显示一些白点(参见图像)。为什么?有什么解决办法吗?
请参阅此图片:
-------------
anim = new TranslateAnimation(0, 360,1000,-100 );
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(10000L);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
btnBalloon.setAnimation(anim);
I used the following segment of code to animate a balloon. Here the balloon is nothing, but the button and it is animating using translate animation.
Animation works fine, but while balloon moving some white dots are displaying (See the Image ). Why? Any Solution?
See this Image:
-------------
anim = new TranslateAnimation(0, 360,1000,-100 );
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(10000L);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
btnBalloon.setAnimation(anim);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有清除每个新帧上的画布。这些点是仍可见的气球先前实例的边缘。
每次绘制画布时,它都不是从头开始,而是在已有的内容之上进行绘制。这意味着每次绘制气球时,它都会绘制在它的所有其他实例之上。我猜你的气球图像有黑色背景?为了解决这个问题,您需要通过在每个帧上重新绘制背景来“清除”画布。在这种情况下,您需要在绘制气球之前绘制一个覆盖整个框架的黑色矩形。
You are not clearing the canvas on each new frame. The dots are the edge of previous instances of the balloon that are still visible.
Each time the canvas is drawn, it does not start from scratch, it draws on top of what's already there. This means that each time the balloon is drawn, it's drawing on top of every other instance of it. I'm guessing your balloon image has a black background? To remedy this, you'll need to 'clear' your canvas, by drawing the background afresh, on each frame. In this case, you'll need to drawn a black rectangle that covers the whole frame, before drawing the balloon.