[当用户点击给定视图时,例如ImageView
,我需要获取触摸区域的确切位置和大小(宽度,高度)。
我看了MotionEvent
。使用以下方法,我可以获得触摸区域的(x,y),但我也需要它的宽度和高度:
public boolean onTouch(View v, MotionEvent event) {
if ( event.getAction() == MotionEvent.ACTION_DOWN ) {
float x = event.getRawX();
float y = event.getRawY();
return true;
}
return false;
}
想法是访问触摸区域的每个像素,以便执行我想执行的操作。因此,理想情况下(如果可能的话)总触摸面积应为使用以下参数定义的正方形:
x - the top-left x position
y - the top-left y position
width - touched area width
height - touched area height
任何帮助将不胜感激。
[请问您是否找到了如何计算接触面积的方法,我需要您的帮助。