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 having an animation file that is :
<?xml version="1.0" encoding="UTF-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="135"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="0"
android:fillAfter="true"
android:fillEnabled="true"
android:duration="100" />
Right now I am using makovkastar library to do this FAB button. However, when I set the FAB to rotate, the shadow rotates along with the FAB button.
Is there any way to just animate the drawable inside the FAB button??
This is how I set my animation
Animation anim = AnimationUtils.loadAnimation(MainActivity.this, R.anim.rotate);
fab.startAnimation(anim);
Yes...what you have to do is to rotate the mActionIcon in FloatingActionButtonClass . See below.
}
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:
We start animation like this:
And stop it:
I wrap FrameLayout in custom view to more comfortable, here is full gist https://gist.github.com/pengrad/9db82de705b58b10c5e9