FloatingActionButton icon indicating copy to clipboard operation
FloatingActionButton copied to clipboard

Support GONE instead of INVISIBLE

Open danpe opened this issue 10 years ago • 6 comments

Sometimes you'll want the FAB to be GONE from the layout after animating. Maybe make INVISIBLE default and add an option to make it use GONE instead?

Thanks, Dan

danpe avatar Jul 05 '15 10:07 danpe

FAB it's an ImageButton. Have you tried just to set its visibility to GONE? Like this: FloatingActionButton.setVisibility(GONE).

Clans avatar Jul 05 '15 10:07 Clans

Of course it works, but it will not play the animation :( currently I'm using this:

    private void hideFab(final FloatingActionButton fab) {
        fab.hide(true);
        fab.setVisibility(GONE);
    }

It's a "patch" and still not perfect because itt makes the Button GONE before animation finishes.

danpe avatar Jul 05 '15 10:07 danpe

I found out this also happening when using fab.hide(true) Without .setVisibility(GONE). it doesn't wait for the animation to finish.

I'm currently using:

    private void hideFab(final FloatingActionButton fab) {
        fab.hide(true);
        fab.getAnimation().setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                fab.setVisibility(GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    private void showFab(final FloatingActionButton fab) {
        fab.setVisibility(INVISIBLE);
        fab.show(true);
    }

I'll make a fix for that an add a pull request :)

danpe avatar Jul 05 '15 10:07 danpe

You can use your own animation and, in that case, the AnimationListener should work.

Clans avatar Jul 05 '15 13:07 Clans

Yes I am setting my own animation using

 app:fab_showAnimation="@anim/fab_scale_up"
 app:fab_hideAnimation="@anim/fab_scale_down"

But still the "patch" function I have is not the best approach, it will be better to have this support in the library, don't you think ?

If so let me know and I'll implement it.

danpe avatar Jul 05 '15 13:07 danpe

I have the same problem. Can't hide FloatingActionButton inside FloatingActionMenu during close animation. If i try to add AnimationListener to Menù animation i get: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.animation.Animation.setAnimationListener(android.view.animation.Animation$AnimationListener)' on a null object reference.

fabMenu.getAnimation() return a null object, also if i set in XML layout the animations: app:fab_showAnimation="@anim/fab_scale_up" app:fab_hideAnimation="@anim/fab_scale_down"

Please help

MajorDeew avatar Apr 16 '20 18:04 MajorDeew