使位图听触摸事件 [英] Make Bitmaps listen to touch events

查看:124
本文介绍了使位图听触摸事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么可以添加触摸功能,以一个简单的的位图吗?

How can I add touch capabilities to a simple bitmap?

我试图创建一个包装类A 的位图
该实施 OnGestureListener
但没有奏效。

I've tried to create a wrapper class for a bitmap,
which implemented OnGestureListener,
but it didn't work.

我想避免扩展视图类来实现这一目标。

I want to avoid extending View class to achieve this.

谢谢!

推荐答案

A 位图本身是一个图像的只是一个再presentation ......因此,为了表现它,你将不得不在某处画它(查看,其实你一直画它放在查看)。那么,有没有办法避免使用查看类,因为所有的用户界面部件扩展它。

A Bitmap per se is just a representation of an image... thus, in order to show it you will have to draw it somewhere (a View, in fact you always draw it on a View). Then, there's no way to avoid using the View class since all user interface widgets extend it.

总之,如果你想简单地设置触摸听众一个位图就可以了,例如,绘制一个 ImageView的,并设置相应的监听器。在另一方面,如果你有一组绘制的某处位图(例如,在 SurfaceView ),你应该找到位图由它的坐标(在这种情况下, 查看这将接收的事件将是 SurfaceView )。

In conclusion, if you want to simply set touch listeners to a single Bitmap you can, for instance, draw it on a ImageView and set the appropriate listeners. On the other hand, if you have a set of bitmaps drawn somewhere (for instance, on a SurfaceView), you should locate the bitmap by its coordinates (in that case, the View which would receive the events will be the SurfaceView).

这篇关于使位图听触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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