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).
To remove shadow of Floating Action Button in Kotlin Android, set the elevation attribute (in layout file) to 0dp or set compatElevation parameter (in Kotlin program) of FAB with floating point value of 0.0f.
To change the shape of the Floating action button: You can use the shape property of FloatingActionButton() widget class. Implement BeveledRectangleBorder( ) on this property. The output will be a square floating action button, increase the border-radius value to make a circular type shape.
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();
public void rotateFabForward() {
ViewCompat.animate(fab)
.rotation(135.0F)
.withLayer()
.setDuration(300L)
.setInterpolator(new OvershootInterpolator(10.0F))
.start();
}
public void rotateFabBackward() {
ViewCompat.animate(fab)
.rotation(0.0F)
.withLayer()
.setDuration(300L)
.setInterpolator(new OvershootInterpolator(10.0F))
.start();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With