I want to display the popup in the position where the user clicked on the screen, I use the function - showAtLocation (mainView, Gravity.TOP or Gravity.START, posX, posY), everything is fine in the x coordinate, but the Y coordinate of the popup is added higher than that place where the user clicked, and if the main view (mainView) is scrolled, then the popup generally flies to the very bottom and I just can't figure out what's wrong with the Y position.
posX and posY is the position where user touch the screen
UPDATED
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
posY = event.y.toInt()
return super.dispatchTouchEvent(event)
}