Skip to content

Instantly share code, notes, and snippets.

@ademar111190
Created June 17, 2019 17:33
Show Gist options
  • Select an option

  • Save ademar111190/59d4be66bab6c11a16fc6e72f43aa49d to your computer and use it in GitHub Desktop.

Select an option

Save ademar111190/59d4be66bab6c11a16fc6e72f43aa49d to your computer and use it in GitHub Desktop.
Step 10, the rect update creator
...
private var index = 0
...
override fun onAttachedToWindow() {
...
child.addOnNavigationItemSelectedListener { updateRectByIndex(it, true) }
post { updateRectByIndex(index, false) }
}
...
private fun updateRectByIndex(index: Int, animated: Boolean) {
this.index = index
target?.apply {
if (childCount < 1 || index >= childCount) return
val reference = getChildAt(index)
val start = reference.left + left
val end = reference.right + left
backgroundDrawable.setBounds(left, top, right, bottom)
val newRect = Rect(start, 0, end, height)
if (animated) startUpdateRectAnimation(newRect) else updateRect(newRect)
}
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment