How to animate FloatingActionButton of new Design Support Library

后端 未结 5 1638
梦谈多话
梦谈多话 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:25

    Because I did not want to extend the FloatingActionButton, I made it this way:

    FloatingActionButton createButton;
    
    // ...
    
    Animation makeInAnimation = AnimationUtils.makeInAnimation(getBaseContext(), false);
    makeInAnimation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) { }
    
        @Override
        public void onAnimationRepeat(Animation animation) { }
    
        @Override
        public void onAnimationStart(Animation animation) {
            createButton.setVisibility(View.VISIBLE);
        }
    });
    
    Animation makeOutAnimation = AnimationUtils.makeOutAnimation(getBaseContext(), true);
    makeOutAnimation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) {
            createButton.setVisibility(View.INVISIBLE);
        }
    
        @Override
        public void onAnimationRepeat(Animation animation) { }
    
        @Override
        public void onAnimationStart(Animation animation) { }
    });
    
    // ...
    
    if (createButton.isShown()) {
        createButton.startAnimation(makeOutAnimation);
    }
    
    // ...
    
    if (!createButton.isShown()) {
        createButton.startAnimation(makeInAnimation);
    }
    

提交回复
热议问题