Find view with given x/y coords in android

前端 未结 1 1167
死守一世寂寞
死守一世寂寞 2021-02-08 20:57

is it possible to find the View that is displayed at a given absolute x/y pixel coord?

Edit: I found a suitable Solution that works great:

private View f         


        
1条回答
  •  不要未来只要你来
    2021-02-08 21:30

    One 'solution' would be to loop through the parent view's children and check the getLeft() and getTop() coordinates against the X and Y coordinates of your choice. If there is a match, you have your view.

    I'd like to hear other alternatives though.

    Edit: You'd also have to work out the height/width of the view too in relation to the left and top coordinates given to see if your coordinates are within that range.

    0 讨论(0)
提交回复
热议问题