Last active
April 17, 2018 06:15
-
-
Save kotoMJ/16c9a651f0901148eb2b9abe33d84b29 to your computer and use it in GitHub Desktop.
Animate FAB to show programatically.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice notes about automatic animations here: https://www.codementor.io/tips/7812274333/android-adding-simple-animations-while-setvisibility-view-gone