我想從它的中心點旋轉圖像單輪,但我不能停止在期望的位置,因爲我可以做旋轉,但我想在360'(1 round)
後停止旋轉。360度後停止圖像旋轉
public class RotateRoundActivity extends Activity implements OnTouchListener
{
private ImageView dialer;
//private float y=0;
private float x=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dialer = (ImageView) findViewById(R.id.big_button);
dialer.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// double r=Math.atan2(event.getX()-dialer.getWidth()/2, dialer.getHeight()/2-event.getY());
double r=Math.atan2(event.getX()-dialer.getWidth()/2, dialer.getHeight()/2-event.getY());
int rotation=(int)Math.toDegrees(r);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
x=event.getX();
// y=event.getY();
updateRotation(rotation);
break;
case MotionEvent.ACTION_UP:
break;
}//switch
return true;
}
旋轉法@
private void updateRotation(double rot){
float newRot=new Float(rot);
Bitmap bitmap=BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
Matrix matrix=new Matrix();
matrix.postRotate(newRot,bitmap.getWidth(),bitmap.getHeight());
Log.i("demo===>", "matrix==>" + matrix);
// Log.i("demo===", "y===>" + y);
Log.i("demo===", "x===>" + x);
if(x>250){
Bitmap reDrawnBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
dialer.setImageBitmap(reDrawnBitmap);
}
else{
Bitmap reDrawnBitmap=Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
dialer.setImageBitmap(reDrawnBitmap);
}
}
}
您的建議是明顯的。
在哪個方向要旋轉?我的意思是順時針/逆時針? – 2012-07-05 09:35:44
在方向時鐘和逆時針。 – Maulik 2012-07-05 09:39:59