【问题标题】:i want implement animation for Floating Button我想为浮动按钮实现动画
【发布时间】:2017-05-02 14:48:22
【问题描述】:

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

这是我的代码,我想要有人修改值或代码

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

【问题讨论】:

    标签: android android-animation floating-action-button


    【解决方案1】:

    在 res/anim 中制作 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);
    

    【讨论】:

    • 如果它在活动中,使用“this”而不是“context”
    猜你喜欢
    • 2015-03-11
    • 2015-07-09
    • 1970-01-01
    • 2015-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多