【问题标题】:How to check position of dragging view is lying over the another view or not如何检查拖动视图的位置是否位于另一个视图之上
【发布时间】:2017-09-16 16:28:41
【问题描述】:
我有这些圆形可拖动按钮,我正在使用 set setTranslationX()
用于拖动功能的 ontouch 事件中的 setTranslationY()。
我如何知道是否有任何按钮拖到图标中间,是否位于中间图标上方?
【问题讨论】:
标签:
java
android
draggable
ontouchlistener
【解决方案1】:
谢谢@Dheerubhai Bansal 最后我完成了使用这种碰撞方法。可以很好地找到两个视图之间的交集
public boolean CheckCollision(View v1, View v2) {
Rect myViewRect = new Rect();
v1.getHitRect(myViewRect);
Rect otherViewRect1 = new Rect();
v2.getHitRect(otherViewRect1);
return Rect.intersects(myViewRect, otherViewRect1);
}