2010-07-06 18 views
3

在Android的開始屏幕上,Android API用於在左側還是右側滾動Android?在開始屏幕上使用的Android手勢

+0

或許,如果你解釋什麼是你要完成你的賞金將得到滿足。通過「開始屏幕」,我假設你的意思是Launcher,它的來源是免費的。如果這不能提供您正在尋找的答案,請考慮解釋您所尋找的是什麼。 – mbafford 2010-07-14 13:37:51

回答

5

最簡單的方法是通過檢測「Fling」手勢。 android API有一個內置的檢測器,用於基本手勢,如拋擲,滾動,長按,雙擊,縮放等。

該文檔可從http://developer.android.com/reference/android/view/GestureDetector.html獲取。

你要做的是創建一個GestureDetector的實例,覆蓋你感興趣檢測手勢的視圖的onTouchEvent方法,並將MotionEvent傳遞給GestureDetector。

您還必須提供一個OnGestureListener實現(最簡單地將SimpleOnGestureListener擴展)到GestureDetector並且將處理所有的手勢事件。

例子:

class MyView extends View 
{ 
    GestureDetector mGestureDetect; 

    public MyView(Context context) 
    { 
     super(context); 
     mGestureDetect = new GestureDetector(new SimpleOnGestureListener() 
     { 

     @Override 
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) 
     { 
     //check if the fling was in the direction you were interested in 
     if(e1.getX() - e2.getX() > 0) 
     { 
     //Do something here 
     } 
     //fast enough? 
     if(velocityX > 50) 
     { 
     //etc etc 
     } 

     return true; 
     } 
     } 
    } 

    public boolean onTouchEvent(MotionEvent ev) 
    { 
     mGestureDetector.onTocuhEvent(ev); 
     return true; 
    } 
} 
1

您正在尋找GestureLibraries班。詳細瞭解它here

我沒有這個使用自己,所以我不能給你更多的信息,但這些也可能是有用的:

Android MotionEvent

Android - Basic Gesture Detection

+0

這意味着我必須基本上創建自己的手勢,並且已經沒有固定的左右手勢了嗎? 該手勢甚至適用於Android 1.5手機的開始屏幕,而鏈接到的類是在Android 1.6中引入的。 – Christian 2010-07-06 16:56:21

+0

@Christian你不必爲一個簡單的事情構建一個複雜的手勢就像一個投擲。有像這樣的常見類型的快速課程。 – CodeFusionMobile 2010-07-13 19:26:39