FloatingActionButton icon indicating copy to clipboard operation
FloatingActionButton copied to clipboard

Menu Hide/Show Animation Center Issue

Open GitUser4732 opened this issue 8 years ago • 3 comments

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

GitUser4732 avatar Aug 03 '17 06:08 GitUser4732

Any solution yet?

anupdey99 avatar Aug 09 '17 18:08 anupdey99

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.

markuspaschi avatar Aug 26 '17 20:08 markuspaschi

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)
}

EdwardvanRaak avatar Feb 15 '20 23:02 EdwardvanRaak