How to rotate floating action button without rotating shadow?

kandi picture kandi · Jul 22, 2015 · Viewed 11.6k times · Source

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).

Answer

srinivasan picture srinivasan · Jul 27, 2015

Did you try with the animate method provided by the Compat library? I too had the same problem when using Animation utils

final OvershootInterpolator interpolator = new OvershootInterpolator();
ViewCompat.animate(fab).
           rotation(135f).
           withLayer().
           setDuration(300).
           setInterpolator(interpolator).
           start();