Clans / FloatingActionButton

Android Floating Action Button based on Material Design specification
Apache License 2.0
5.23k stars 1.13k forks source link

Menu Hide/Show Animation Center Issue #409

Open GitUser4732 opened 7 years ago

GitUser4732 commented 7 years ago

When hiding and showing menu button the animation is not centered on the button but the entire view group's(Button ,menu buttons and labels) bounds. How can I have these animations look similar to the normal FAB and animate to the buttons center and not the entire viewgroup?

Thanks

anupdey99 commented 7 years ago

Any solution yet?

markuspaschi commented 7 years ago

what i did:

            fab:menu_fab_hide_animation="@anim/fade_out"
            fab:menu_fab_show_animation="@anim/fade_in"

is not perfect, but at least doesn't affect the groups layout. It stays in place.

EdwardvanRaak commented 4 years ago

For anyone still using this lib or one of its forks, these extensions I made worked for me, it uses the icon inside the primary FAB as the pivot point.

In some cases you might need to wrap the code inside the function in a post{ } block.

fun FloatingActionMenu.show() {
    if (visibility != View.VISIBLE) {
        val pivotX = menuIconView.pivotX + menuIconView.x
        val pivotY = menuIconView.pivotY + menuIconView.y

        val anim = ScaleAnimation(
            0f, 1f, 0f, 1f, Animation.ABSOLUTE, pivotX,
            Animation.ABSOLUTE, pivotY
        )
        anim.duration = 200
        anim.interpolator = LinearInterpolator()
        startAnimation(anim)
    }
    visibility = View.VISIBLE
    close(false)
}
fun FloatingActionMenu.hide() {
    if (visibility == View.VISIBLE) {
        val pivotX = menuIconView.pivotX + menuIconView.x
        val pivotY = menuIconView.pivotY + menuIconView.y

        val anim = ScaleAnimation(
            1f, 0f, 1f, 0f, Animation.ABSOLUTE, pivotX,
            Animation.ABSOLUTE, pivotY
        )
        anim.duration = 200
        anim.interpolator = LinearInterpolator()
        startAnimation(anim)
    }
    visibility = View.INVISIBLE
    close(false)
}