Guest User

Untitled

a guest
Jan 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class MainActivity : AppCompatActivity() {
  2.  
  3. override fun onCreate(savedInstanceState: Bundle?) {
  4. super.onCreate(savedInstanceState)
  5. setContentView(R.layout.activity_main)
  6.  
  7. val items = listOf<AppCompatEditText>(et1, et2, et3, et4, et5, et6, et7, et8, et9, et10, et11, et12,
  8. et13, et14, et15, et16, et17, et18, et19, et20, et21, et22, et23)
  9.  
  10. items.forEachIndexed { index, et -> et.hint = "index : $index" }
  11.  
  12. scrollView.viewTreeObserver.addOnGlobalFocusChangeListener { old, _ ->
  13. // TODO : how to check next focus edittext
  14. old?.takeIf { keyboardIsShow() }?.apply {
  15. scrollView.smoothScrollTo(0, scrollView.scrollY.plus(120))
  16. }
  17. }
  18. }
  19. }
  20.  
  21. // TODO : move to file UIExtensions
  22. fun Activity.keyboardIsShow(): Boolean = let {
  23. var flag = false
  24. val rect: Rect by lazy { Rect() }
  25. window.decorView.rootView?.apply {
  26. getWindowVisibleDisplayFrame(rect)
  27. flag = (bottom - rect.bottom) > (100 * resources.displayMetrics.density)
  28. }
  29. flag
  30. }
Add Comment
Please, Sign In to add comment