Android接触区域的坐标和尺寸:宽度和高度

问题描述 投票:0回答:1

[当用户点击给定视图时,例如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 

任何帮助将不胜感激。

android touch ontouchlistener touch-event motionevent
1个回答
0
投票

[请问您是否找到了如何计算接触面积的方法,我需要您的帮助。

© www.soinside.com 2019 - 2024. All rights reserved.