How to animate FloatingActionButton of new Design Support Library

后端 未结 5 1655
梦谈多话
梦谈多话 2020-12-28 09:06

I am using a TabLayout with 5 different fragments. On 3 of these fragments a android.support.design.widget.FloatingActionButton should appear. Right now I simpl

5条回答
  •  渐次进展
    2020-12-28 09:23

    The easiest way is to extend the FloatingActionButton class and override setVisibility. Like this:

    public void setVisibility(final int visibility) {
        if (getVisibility() != View.VISIBLE && visibility == View.VISIBLE && inAnim != null) {
            animator = // create your animator here
            super.setVisibility(visibility);
        } else if (getVisibility() == View.VISIBLE && visibility != View.VISIBLE) {
            AnimatorListenerAdapter listener = new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    Button.super.setVisibility(visibility);
                }
            });
            animator = // create your animator here
            animator.addListener(listener);
        }
    }
    

    The code above is taken from the Button class from my library. You can find sample implementations in sources.

提交回复
热议问题