事件侦听器添加到形状,android.graphics包 [英] Add event listeners to shapes in android.graphics package

查看:92
本文介绍了事件侦听器添加到形状,android.graphics包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新到Android编程和放大器;我试图创建一个简单的程序,我可以处理拖放放大器;触摸不同形状的事件。

I am new to android programming & I'm trying to create a simple program where I can handle drag & touch events on different shapes.

从Android API,我明白,这是很容易事件侦听器添加小部件(如:ImageView的)。但我怎么做同样的图形,如RectF或圆?

From the android API, I understand that it is easy to add event listeners to widgets(eg:ImageView). But how do I do the same for graphics such as RectF or Circle?

由于我是新手,我会AP preciate,如果有人可以解释更简单的条款。

Since I'm a novice, I would appreciate if someone could explain in simpler terms.

推荐答案

喜欢的 OnClickListeners 只能被添加到查看类。

Things like OnClickListeners can only be added to subsets of the View class.

不过,对于形状等,您可以覆盖你的基地布局onTouch()方法。然后在 MotionEvent.ACTION_DOWN 你得到触摸点的坐标,看看他们是否与您的任何形状的相交。如果它的形状相交,然后用户点击了形状,和C你需要,你可以实现任何$ C $。

However, for shapes etc. you can override the onTouch() method for your base layout. Then in MotionEvent.ACTION_DOWN you get the coordinates of the touch point, and see if they intersect with any of your shapes. If it intersects with a shape, then the user clicked that shape, and you can implement whatever code you need to.

这篇关于事件侦听器添加到形状,android.graphics包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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