What I am trying to do: I am trying to determine .... If any part of one view crosses other view
What I have done:
Usage: isDragOverlap = textView.isOverlap(buttonView)
Code:
private fun View.isOverlap(other: View, deltaX: Int = 0, deltaY: Int = 0): Boolean {
val thisXY = IntArray(2).apply { getLocationOnScreen(this) }
val otherXY = IntArray(2).apply { other.getLocationOnScreen(this)
this[0] += deltaX
this[1] += deltaY
}
return thisXY.let {
Rect(it[0], it[1], it[0] + width, it[1] + height)
}
.intersect(otherXY.let {
Rect(it[0], it[1], it[0] + other.width, it[1] + other.height)
}
)
}
Above code works as: Here below intersection is detected
What is not working: Here below intersection is not detected

