Skip to content

Instantly share code, notes, and snippets.

@NielsMasdorp
Created September 11, 2018 15:40
Show Gist options
  • Save NielsMasdorp/f0aac6c0644546390cab0ef43123c8b3 to your computer and use it in GitHub Desktop.
Save NielsMasdorp/f0aac6c0644546390cab0ef43123c8b3 to your computer and use it in GitHub Desktop.
Increase touchable area of view without increasing its size
private fun changeTouchableAreaOfView(view: View, extraSpace: Int) {
    val parent = view.parent as View
    parent.post {
        val touchableArea = Rect()
        button.getHitRect(touchableArea)
        touchableArea.top -= extraSpace
        touchableArea.bottom += extraSpace
        touchableArea.left -= extraSpace
        touchableArea.right += extraSpace
        parent.touchDelegate = TouchDelegate(touchableArea, button)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment