Android get bounding rectangle of a View

后端 未结 5 619
渐次进展
渐次进展 2020-12-08 02:17

I\'m implementing a drag and drop for an Android application. In order to know if the drop happens inside the drop target, I need to know the bounding rectangle of the drop

5条回答
  •  情话喂你
    2020-12-08 02:43

    Using getGlobalVisibleRect:

    val rect = Rect()
    view.getGlobalVisibleRect(rect)
    val isContainedInView = rect.contains(x, y)
    

提交回复
热议问题