在给定的像素位置有一个视图。我有像素的坐标。如何在给定的坐标中查找视图的ID?坐标系中的视图ID
4
A
回答
1
我觉得这样的事情应该工作:
走你的视图结构,找到孩子的意见(即那些没有子视图)是可见的。
使用View.getLocationOnScreen()在你的视图来检索他们的位置(上/左窗口坐标)
使用getMeasuredWidth()/ getMeasuredHeight()来获取视图的宽度和高度
看看你的这个像素矩形内的坐标落在
3
如果你是ViewGroup
内:
int count = viewgroup.getChildCount();
for (int i = 0; i < count; i++)
{
View view = viewgroup.getChildAt(i);
if (view.getX() == theX && view.getY() == theY)
return view.getId()
}
EDIT(kcoppock):中的for循环,我会做这样的事情:
View view = viewgroup.getChildAt(i);
if(!view.getVisibility() == View.VISIBLE) continue;
int[] location = {0, 0};
view.getLocationOnScreen(location);
int right = location[0] + view.getWidth();
int bottom = location[1] + view.getHeight();
Rect bounds = new Rect(location[0], location[1], right, bottom);
if(bounds.contains(coordinatesX, coordinatesY)) return view.getId();
相关问题
- 1. ios视图坐标系
- 2. 了解Qt的图形视图坐标系统
- 3. Android中的屏幕和视图坐标
- 4. Cocos2D中的坐标系
- 5. Android中事件坐标和视图坐标不匹配?
- 6. 查找图像视图内的坐标?
- 7. 将视图端口坐标转换为实际图像坐标
- 8. iOS目标C将坐标从绝对图像位置转换为我的视图坐标系
- 9. WPF坐标系
- 10. PDFBox - 坐标系
- 11. D3D11坐标系
- 12. libGDX坐标系
- 13. Matlab坐标系?
- 14. OpenLayer坐标系
- 15. MKOverlayView坐标系
- 16. 如何将图像视图的坐标转换为位图的坐标?
- 17. JAVA GUI图形上的坐标系
- 18. 带坐标和横坐标的坐标系
- 19. 图像变换坐标,圆柱坐标系
- 20. 在SpriteKit旋转坐标系统中的视场中
- 21. 如何将子视图上的触摸事件的坐标转换为其父视图中的坐标?
- 22. PyQt将鼠标按钮的坐标映射到图像的坐标系
- 23. UITabBar子视图的Y坐标
- 24. 旋转视图的onTouch错误坐标
- 25. 图像视图w.r.t到根视图的本地坐标
- 26. Android屏幕坐标到画布视图坐标
- 27. SVG - 从窗口坐标到视图框坐标
- 28. 转换视图点击坐标从世界坐标到本地?
- 29. 如何将iPhone摄像头坐标转换为视图坐标?
- 30. iPhone,cocos2d坐标系
这已经很接近,但只打算当他点击左上角的确切像素的工作的观点。我会在一个建议中编辑。 – kcoppock 2012-07-12 15:03:20
确切地感谢您编辑 – Blackbelt 2012-07-12 15:04:59
。您还需要确保getChildAt()返回可见的视图(getVisibility()== View.VISIBLE) – CSmith 2012-07-12 15:14:38