在Android中随机路径动画效果的ImageView [英] Animating a imageview on a random path in Android

查看:1297
本文介绍了在Android中随机路径动画效果的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个任务似乎相当简单,但我不知道什么是执行它在Android的最佳方式。

The task seems fairly simple but I don't know what's the best way to implement it in Android.

应该如何看待

应该有一个数字在屏幕上的图像(比方说4-5最大值)每个图像都将作为背景FrameAnimation这是一次性的(假)(重新presenting正在运行的男人)。这些图像需要有按照屏幕,它的首次创建时左右计算随机路径。所以,跑步的人会在不同的方向在屏幕上。每个图像将有一个的onClick侦听器,这样就可以点击时,它会从屏幕上消失。

There should be a number of images on the screen (let's say 4-5 max) each image will have as a Background a FrameAnimation that's oneTime(false) (representing a running man). Each of these images need to have a random path to follow around the screen, calculated when it's first created. So the running man will go around the screen in different directions. Each image will have a onClick listener so when clicked on it, it will be removed from the screen.

什么是做这在Android中开始1.6,而不会造成性能的下降或位内存泄漏的最佳方法?

What is the best way to do this in Android starting with 1.6 without causing performance drops or Bitmap Memory leaks ?

我附上图像例证。谢谢大家的时间。

I attach a image for exemplification. Thank you all for your time.

后来编辑:最好的解决方案似乎使用一个扩展SurfaceView。我看到一些样品添加,走动的形象,但我还不知道我怎么能拦截onTouchEvent。我可以覆盖surfaceView的onTouchEvent。现在来在我脑海中的解决方案是让现场感动的X和Y,然后看看在动画图像如果有的话是X,Y pressed点之下。这似乎是pretty复杂。

Later the best solution seems to use a extended SurfaceView. I saw some samples with adding, moving the image around, but I don't know yet how could I intercept the onTouchEvent. I can override the onTouchEvent of the surfaceView. The solution that comes now in my mind is get x and y of the touched spot and then look in the animated images if any is under the x,y pressed spot. This seems pretty complicate.

推荐答案

每个运行精灵都会有其矩形cooridantes;左上角和右下角。所有你需要做的是遍历你的精灵,看看用户触摸的点,其中x和y是一个精灵的矩形内。

Each running sprite will have its rectangle cooridantes; top-left and bottom right. All you need to do is to loop through your sprites and see if the user has touched a point where x and y are within a sprite's rectangle.

然而,你将不得不同步{} code的一些街区,以及...

However you will have to synchronize{} some blocks of code as well...

这篇关于在Android中随机路径动画效果的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆