This code is for observing your keyboard
with(binding.root) {
viewTreeObserver.addOnGlobalLayoutListener {
val r = Rect()
getWindowVisibleDisplayFrame(r)
val screenHeight = rootView.height
val keypadHeight = screenHeight - r.bottom
if (keypadHeight > screenHeight * 0.15) {
if (!isKeyboardShowing) {
isKeyboardShowing = true
// binding.box.isVisible = true
with(binding.scroll) {
post {
// smoothScrollTo(0, binding.genderText.y.toInt() - 170)
fullScroll(ScrollView.FOCUS_DOWN)
}
}
}
} else {
if (isKeyboardShowing) {
isKeyboardShowing = false
// binding.box.isVisible = false
}
}
}
}
if view is hidden due to showing keyboard