【问题标题】: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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多