如何在不旋转阴影的情况下旋转浮动动作按钮? [英] How to rotate floating action button without rotating shadow?

查看:94
本文介绍了如何在不旋转阴影的情况下旋转浮动动作按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以一种简单的方式旋转FAB:

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>

这可以工作,但是阴影与FAB一起旋转.但是我只需要旋转FAB(如果有任何区别,甚至可以旋转它的src图像).

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

推荐答案

您尝试使用Compat库提供的动画方法吗?使用Animation utils时我也遇到同样的问题

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();

这篇关于如何在不旋转阴影的情况下旋转浮动动作按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆