2011-09-14 38 views
0

您好,我需要在我的應用程序的觸摸如何在兩個方向旋轉圖像的Android

旋轉的ImageView的,我用下面的代碼

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.createBitmap(itembmp, 0, 0,itembmp.getWidth(), itembmp.getHeight(), matrix, true); 
itembmp=redrawnBitmap; 
image.setImageBitmap(itembmp); 
} 

而是利用這個我可以旋轉僅在時鐘方向上的圖像。

但我需要在兩個方向旋轉圖像。

如何做到這一點。

+0

你想申請什麼旋轉邏輯? (一般來說,你應該給你的'postRotate()'func)一個負值 – MeLight

+0

如何通過onTouchListener知道它是順時針還是逆時針旋轉 – surendra

+0

所以你想知道如何知道如何應用旋轉?換句話說,屏幕在哪裏? – MeLight

回答

0

我會做兩個函數,一個叫updateRotationClockwise,一個叫updateRotationCounterClockWise。

在順時針方向,它應該保持:

matrix.postRotate(10); 

逆時針,應該說:

matrix.postRotate(350); 
+1

如何通過onTouchListener知道它是順時針還是逆時針旋轉 – surendra

0

我在開發這個邏輯的過程。 1.角度差異。還需要檢查其他邊界條件以獲得更高的準確性。 2.而不是處理觸摸操作。我使用構建ScaleGestureDetector類來獲取信息。 在onScaleBegin中,假設我在OnScaleGestureListener中使用setter(on touch)中獲取事件。 before = gety/getx; 在ScaleEnd after = gety/getx;

因此,如果逆時針順時針旋轉,則差值爲tan-1(之前)-tan-1(之後) 。 這是不是很準確,我添加條件,但可以試試這個。