Skip to content

Instantly share code, notes, and snippets.

@kotoMJ
Last active April 17, 2018 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotoMJ/16c9a651f0901148eb2b9abe33d84b29 to your computer and use it in GitHub Desktop.
Save kotoMJ/16c9a651f0901148eb2b9abe33d84b29 to your computer and use it in GitHub Desktop.
Animate FAB to show programatically.
import android.support.design.widget.FloatingActionButton
import android.view.View
import android.view.ViewTreeObserver
fun FloatingActionButton.showWithAnimation(delay: Int = 200) {
visibility = View.INVISIBLE
scaleX = 0.0f
scaleY = 0.0f
alpha = 0.0f
viewTreeObserver.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
viewTreeObserver.removeOnPreDrawListener(this)
postDelayed({ show() }, delay.toLong())
return true
}
})
}
@kotoMJ
Copy link
Author

kotoMJ commented Apr 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment