Android编程实现仿iphone抖动效果的方法(附源码下载)

2019-12-10 19:52:50于海丽
  • mtv14 = (TextView) findViewById(R.id.tv14);  mtv14.setOnClickListener(this); 
  • mtv15 = (TextView) findViewById(R.id.tv15);  mtv15.setOnClickListener(this); 
  • mtv16 = (TextView) findViewById(R.id.tv16);  mtv16.setOnClickListener(this); 
  • mtv17 = (TextView) findViewById(R.id.tv17);  mtv17.setOnClickListener(this); 
  • mtv18 = (TextView) findViewById(R.id.tv18);  mtv18.setOnClickListener(this); 
  • mtv19 = (TextView) findViewById(R.id.tv19);  mtv19.setOnClickListener(this); 
  • }  @Override 
  • public void onClick(View v) {  if (!mStartShake) { 
  • mStartShake = true;  mNeedShake = true; 
  • shakeAnimation(mtv0);  shakeAnimation(mtv1); 
  • shakeAnimation(mtv2);  shakeAnimation(mtv3); 
  • shakeAnimation(mtv4);  shakeAnimation(mtv5); 
  • shakeAnimation(mtv6);  shakeAnimation(mtv7); 
  • shakeAnimation(mtv8);  shakeAnimation(mtv9); 
  • shakeAnimation(mtv10);  shakeAnimation(mtv11); 
  • shakeAnimation(mtv12);  shakeAnimation(mtv13); 
  • shakeAnimation(mtv14);  shakeAnimation(mtv15); 
  • shakeAnimation(mtv16);  shakeAnimation(mtv17); 
  • shakeAnimation(mtv18);  shakeAnimation(mtv19); 
  • }  } 
  • private void shakeAnimation(final View v) {  float rotate = 0; 
  • int c = mCount++ % 5;  if (c == 0) { 
  • rotate = DEGREE_0;  } else if (c == 1) { 
  • rotate = DEGREE_1;  } else if (c == 2) { 
  • rotate = DEGREE_2;  } else if (c == 3) { 
  • rotate = DEGREE_3;  } else { 
  • rotate = DEGREE_4;  } 
  • final RotateAnimation mra = new RotateAnimation(rotate, -rotate, ICON_WIDTH * mDensity / 2, ICON_HEIGHT * mDensity / 2);  final RotateAnimation mrb = new RotateAnimation(-rotate, rotate, ICON_WIDTH * mDensity / 2, ICON_HEIGHT * mDensity / 2);