Android 动画的暂停与播放与匀速

暂停与播放需要是同一个动画实体。


主要代码如下:

 if(MyApplication.MainFABRotation==null){
                    MyApplication.MainFABRotation = ObjectAnimator.ofFloat(main_fab,"rotation",0f,360f);
                    //重复次数
                    MyApplication.MainFABRotation.setRepeatCount(ValueAnimator.INFINITE);
                    //执行时间
                    MyApplication.MainFABRotation.setDuration(3000);
                    //设置动画匀速运动
                    LinearInterpolator lin = new LinearInterpolator();
                    MyApplication.MainFABRotation.setInterpolator(lin);
                    //结束后的状态
                    MyApplication.MainFABRotation.setRepeatMode(ValueAnimator.RESTART);
                }

                if(MyApplication.isPlaying){
                    //设置成playing的图片
                    playOrPause.setImageResource(R.drawable.playing);
                    MyApplication.MainFABRotation.start();
                }
                else{
                    playOrPause.setImageResource(R.drawable.pausing);
                        //然后添加动画---停止旋转
                    if(MyApplication.MainFABRotation.isRunning()){
                        MyApplication.MainFABRotation.pause();
                    }
                }

你可能感兴趣的:(MTMusic制作心得)