假设我在画布上绘制了位图图像或简单的圆圈。如何设置 OnTouchListener 来检查我的绘图是否被触摸?由于我将在画布上绘制多个圆圈,因此我希望每个圆圈都有一些唯一的 ID,以便我可以相应地工作。
当您触摸屏幕时,获取 x 和 y 坐标。你已经知道圆的中心了。
//x and y are co-ordiantes when touched.
//center_x and center_y are co-ordinates of the center of the circle.
//R is the radius of the cirlcr
float dx = Math.abs(x-center_x);
float dy = Math.abs(y-center_y);
float R = radius ;//radius of circle.
boolean checkDistance(float dx,float dy,float R)
{
if(dx>R)
{
return false;//outside
}
else if(dy>R)
{
return false;//
}
else
{
return true;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)