How to rotate floating action button without rotating shadow?

后端 未结 4 1754
一个人的身影
一个人的身影 2021-01-02 01:26

I rotate the FAB in such a simple way:

fab.startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate));

rotate.xml:

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-02 01:53

    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 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 an OvershootInterpolator, then set toDegrees to 90 and animate the level up to the value of 5000 so it doesn't go beyond the bounds.

提交回复
热议问题