今天分享一篇按钮控制动画暂停开始的代码
自己研究了音乐播放器的动画暂停播放功能:先看看图片按播放,滚轮转动,按暂停滚轮则挺住,下面是代码的实现
public class SongPlayActivity extends Activity{int image[] ;//播放,暂停改变图片int num=1;//播放暂停计数参ImageView play_stop,zhuanpan,mReturn;//播放键和转盘ObjectAnimator animator;//用来控制动画的类@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_song_play);initView();zhuanpanAnimator();}/*** 注册*/private void initView() {play_stop = (ImageView) findViewById(R.id.iv_play_pause);zhuanpan =(ImageView) findViewById(iv_xuanzhuan);image =new int[]{ R.mipmap.bfzn_003,R.mipmap.bfzn_004};}public void songPlayReturn(View v){Intent intent =new Intent(SongPlayActivity.this,MainActivity1.class);startActivity(intent);}/*** 旋转动画* @param v*/public void zhuanpanAnimator(){animator = ObjectAnimator.ofFloat(zhuanpan,"rotation",0,360);LinearInterpolator lin = new LinearInterpolator();animator.setInterpolator(lin);animator.setRepeatCount(ValueAnimator.INFINITE);animator.setDuration(10000);animator.start();}@TargetApi(Build.VERSION_CODES.KITKAT)public void playAndStop(View v){play_stop.setImageResource(image[num]);// Animation animation= AnimationUtils.loadAnimation(this, R.anim.rotate);if(num==0){// animationanimator.resume();num=1;}else if (num==1){animator.pause();num=0;// Toast.makeText(SongPlayActivity.this, "111", Toast.LENGTH_SHORT).show();}}}