2017-05-02 113 views
1

我想给我的浮动按钮全旋转动画,我有代码,但它唯一的动画像旋转的一半。我想从一个位置旋转浮动按钮,它应该以它开始的位置(完整旋转)结束,该怎么做?我想实现浮动按钮的动画

这里是我的代码,我希望有人来修改RES值或代码

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

回答

1

制作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:repeatCount="0" 
     android:duration="1000" /> 

</set> 

然后在代码:

FloatingActionButton mFloatingButton = view.findViewById(R.id.myFloatingButton); 

     Animation mAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate); 

     mFloatingButton.startAnimation(mAnimation); 
+0

得到错误,如无法解析符号的上下文 –

+1

使用“this”,而不是“上下文”,如果它处于活动状态 –