如果我知道坐标(X,Y) 像素(通过OnTouchEvent 方法和getX(),getY)我如何找到元素ex。按钮或文本等....使用X,Y
最佳答案
您可以对每个 subview 使用 getHitRect(outRect)
并检查该点是否在生成的矩形中。这是一个快速示例。
for(int _numChildren = getChildCount(); --_numChildren)
{
View _child = getChildAt(_numChildren);
Rect _bounds = new Rect();
_child.getHitRect(_bounds);
if (_bounds.contains(x, y)
// In View = true!!!
}
希望对您有所帮助,
模糊逻辑
关于android - 如何通过坐标 x,y Android 在 View 中查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10959400/