使位图监听触摸事件
如何向简单的位图添加触摸功能?
我尝试为位图创建一个包装类,
实现了 OnGestureListener
,
但没有成功。
我想避免扩展 View 类来实现此目的。
谢谢!
How can I add touch capabilities to a simple bitmap?
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.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
位图本身只是图像的表示...因此,为了显示它,您必须将其绘制在某个地方(一个视图,事实上您总是将其绘制在
View
上)。然后,就无法避免使用View
类,因为所有用户界面小部件都扩展了它。总之,如果您想简单地将触摸侦听器设置为单个位图,例如,您可以将其绘制在 ImageView 上并设置适当的侦听器。另一方面,如果您在某处绘制了一组位图(例如,在
SurfaceView
上),则应通过其坐标来定位位图(在这种情况下,View
接收事件的 code> 将会是 SurfaceView)。A
Bitmap
per se is just a representation of an image... thus, in order to show it you will have to draw it somewhere (aView
, in fact you always draw it on aView
). Then, there's no way to avoid using theView
class since all user interface widgets extend it.In conclusion, if you want to simply set touch listeners to a single
Bitmap
you can, for instance, draw it on aImageView
and set the appropriate listeners. On the other hand, if you have a set of bitmaps drawn somewhere (for instance, on aSurfaceView
), you should locate the bitmap by its coordinates (in that case, theView
which would receive the events will be theSurfaceView
).您是否已将 OnGestureListener 实现连接到 GestureDetector? GestureDetector 分析 MotionEvent 并根据其发现的运动类型在侦听器上调用适当的回调。
Do you have your OnGestureListener implementation wired to a GestureDetector? The GestureDetector analyzes a MotionEvent and invokes the appropriate callback on the listener based on the type of movement it found.