I rotate the FAB in such a simple way:
fab.startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate));
rotate.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"/>
</set>
This works, but together with the FAB its shadow rotates. But I need only the FAB to rotate (or even its src image, if there's any difference).
There's an entirely another approach that works flawlessly for me (the one suggested in the accepted answer produces a clipped shadow on pre-L). Create an XML drawable and wrap your FAB icon into a
<rotate>
tag like this:Set this drawable to your FAB, and animate either its level directly or the
imageLevel
property of the FAB itself; it goes from 0 to 10000. If you'd like anOvershootInterpolator
, then settoDegrees
to 90 and animate the level up to the value of 5000 so it doesn't go beyond the bounds.Did you try with the animate method provided by the Compat library? I too had the same problem when using Animation utils