I believe most of you all have seen the rotating FloatingActionButton in apps such as Google keep, push bullet and even Google inbox app. I am trying to achieve this rotation by
I found that on pre-Lollipop shadow is rotating, but on API >= 21 everything is right.
So, on pre-Lollipop I've tried to rotate an ImageView over FAB. And it works great.
Here is layout where we place ImageView with same source image over FAB:
android:id="@+id/rotatingFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end">
We start animation like this:
public void startAnimation(Animation animation) {
if (Build.VERSION.SDK_INT >= 21) {
mFab.startAnimation(animation);
} else {
mFabImage.setVisibility(VISIBLE);
// need post() to image could measure its size
mFabImage.post(() -> mFabImage.startAnimation(animation));
}
}
And stop it:
public void clearAnimation() {
if (Build.VERSION.SDK_INT >= 21) {
mFab.clearAnimation();
} else {
mFabImage.clearAnimation();
mFabImage.setVisibility(GONE);
}
}
I wrap FrameLayout in custom view to more comfortable, here is full gist https://gist.github.com/pengrad/9db82de705b58b10c5e9