Skip to content

Commit a3b5e01

Browse files
Use setLayerType for animations
This helps animations run smoothly when there's a lot going on.
1 parent 83bc408 commit a3b5e01

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

library/src/main/java/com/getbase/floatingactionbutton/FloatingActionsMenu.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.getbase.floatingactionbutton;
22

3+
import android.animation.Animator;
4+
import android.animation.AnimatorListenerAdapter;
35
import android.animation.AnimatorSet;
46
import android.animation.ObjectAnimator;
57
import android.content.Context;
@@ -469,13 +471,30 @@ public void setAnimationsTarget(View view) {
469471

470472
// Now that the animations have targets, set them to be played
471473
if (!animationsSetToPlay) {
474+
addLayerTypeListener(mExpandDir, view);
475+
addLayerTypeListener(mCollapseDir, view);
476+
472477
mCollapseAnimation.play(mCollapseAlpha);
473478
mCollapseAnimation.play(mCollapseDir);
474479
mExpandAnimation.play(mExpandAlpha);
475480
mExpandAnimation.play(mExpandDir);
476481
animationsSetToPlay = true;
477482
}
478483
}
484+
485+
private void addLayerTypeListener(Animator animator, final View view) {
486+
animator.addListener(new AnimatorListenerAdapter() {
487+
@Override
488+
public void onAnimationEnd(Animator animation) {
489+
view.setLayerType(LAYER_TYPE_NONE, null);
490+
}
491+
492+
@Override
493+
public void onAnimationStart(Animator animation) {
494+
view.setLayerType(LAYER_TYPE_HARDWARE, null);
495+
}
496+
});
497+
}
479498
}
480499

481500
@Override

0 commit comments

Comments
 (0)