hi i need to rotate an ImageView in my app on touch
and i am using the following code
public android.view.View.OnTouchListener onTableTouched = new android.view.View.OnTouchListener(){
public boolean onTouch(View v, MotionEvent evt) {
WrapMotionEvent event = WrapMotionEvent.wrap(evt);
ImageView view = (ImageView) v;
// Dump touch event to log
dumpEvent(event);
//
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_POINTER_DOWN:
mode = NONE;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
if(mode == NONE){
updateRotation();
}
break;
}
return true;
}
};
private void updateRotation()
{
matrix.postRotate(10);
Bitmap redrawnBitmap = Bitmap.createBit开发者_StackOverflow中文版map(itembmp, 0, 0,itembmp.getWidth(), itembmp.getHeight(), matrix, true);
itembmp=redrawnBitmap;
image.setImageBitmap(itembmp);
}
but by using this i can rotate the image in clock-direction only.
But i need to rotate the image in both directions .
How to do that.
I would make two functions, one called updateRotationClockwise, one called updateRotationCounterClockWise.
In clockwise, it should stay:
matrix.postRotate(10);
In counterclockwise, it should say:
matrix.postRotate(350);
I am in process of developing this logic. 1. Difference in angle. one needs to also check other boundary conditions for more accuracy. 2. Instead of handling touch actions. I used in build ScaleGestureDetector class for information. In onScaleBegin assuming I get the event using a setter (called in on touch) in the OnScaleGestureListener. before=gety/getx; In on ScaleEnd after=gety/getx;
thus difference is tan-1(before)-tan-1(after) if +tive anticlockwise -tive clockwise. It is not so accurate I am adding conditions but one can try this out.
from the class ClockView you can find the method for rotation for your bitmap image
https://github.com/jselbie/xkcdclock
精彩评论