最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android使用gesturedetector手勢識別示例分享

 更新時間:2014年01月11日 14:26:16   作者:  
這篇文章主要介紹了android使用手勢識別的方法,介紹了單擊觸摸屏觸發(fā)的事件和雙擊事件的使用等方法,大家參考使用吧

復制代碼 代碼如下:

public class MyGestureLintener extends SimpleOnGestureListener {
private Context context;
public MyGestureLintener(Context context) {
    super();
    this.context = context;
}

// 單擊,觸摸屏按下時立刻觸發(fā)
/*@Override
public boolean onDown(MotionEvent e) {
    // TODO Auto-generated method stub
    Toast.makeText(context, "Down " + e.getAction(), Toast.LENGTH_SHORT)
        .show();
    return true;
}*/
// 雙擊,手指在觸摸屏上迅速點擊第二下時觸發(fā)
@Override
public boolean onDoubleTap(MotionEvent e) {
    // TODO Auto-generated method stub
    return super.onDoubleTap(e);
}

// 雙擊的按下跟抬起各觸發(fā)一次
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    // TODO Auto-generated method stub
    return super.onDoubleTapEvent(e);
}

 

// 滑動,觸摸屏按下后快速移動并抬起,會先觸發(fā)滾動手勢,跟著觸發(fā)一個滑動手勢
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    // TODO Auto-generated method stub
    return super.onFling(e1, e2, velocityX, velocityY);
}

// 長按,觸摸屏按下后既不抬起也不移動,過一段時間后觸發(fā)
@Override
public void onLongPress(MotionEvent e) {
    // TODO Auto-generated method stub
    Toast.makeText(context, "LONG " + e.getAction(), Toast.LENGTH_SHORT)
            .show();
}

// 滾動,觸摸屏按下后移動
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
        float distanceY) {
    Toast.makeText(context, "onScroll " + e2.getAction(), Toast.LENGTH_SHORT)
    .show();
    return true;
}

// 短按,觸摸屏按下后片刻后抬起,會觸發(fā)這個手勢,如果迅速抬起則不會
@Override
public void onShowPress(MotionEvent e) {
    // TODO Auto-generated method stub
    Toast.makeText(context, "Show " + e.getAction(), Toast.LENGTH_SHORT)
            .show();

}

// 單擊確認,即很快的按下并抬起,但并不連續(xù)點擊第二下
/*@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    // TODO Auto-generated method stub
    Toast.makeText(context, "onSingleTapConfirmed " + e.getAction(), Toast.LENGTH_SHORT)
    .show();
    return true;
}*/

// 抬起,手指離開觸摸屏時觸發(fā)(長按、滾動、滑動時,不會觸發(fā)這個手勢)
/*@Override
public boolean onSingleTapUp(MotionEvent e) {
    // TODO Auto-generated method stub

    Toast.makeText(context, "onSingleTapUp " + e.getAction(), Toast.LENGTH_SHORT)
    .show();
    return true;
}*/
public class MainActivity extends Activity {
private GestureDetector mGestureDetector;//手勢對象
private MyGestureLintener myGestureLintener;//手勢監(jiān)聽的接口對象

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    myGestureLintener = new MyGestureLintener(this);

    //手勢對象的構(gòu)造方法
    mGestureDetector = new GestureDetector(this,
            myGestureLintener);
}

/**GestureDetector類的onTouchEvent方法用來辨別不同的手勢*/
@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean b = false;
    int i = event.getAction();
    int j = MotionEvent.ACTION_MOVE;
    System.out.println(i+"<----------------->"+j);
    b = mGestureDetector.onTouchEvent(event);
    if (b) {
        Intent in = new Intent();
        in.setClass(this, testActivity.class);
        startActivity(in);
    }
    return b;

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

相關(guān)文章

最新評論

科技| 南涧| 兴和县| 疏附县| 正镶白旗| 西峡县| 始兴县| 太原市| 玛纳斯县| 葵青区| 博客| 阳春市| 汤阴县| 靖江市| 饶河县| 蒲城县| 普兰县| 宜宾市| 东宁县| 万全县| 东莞市| 营口市| 陇南市| 金堂县| 兴隆县| 栾川县| 米林县| 洪泽县| 永福县| 积石山| 磐安县| 三亚市| 五家渠市| 休宁县| 东方市| 南木林县| 蒲江县| 武山县| 若尔盖县| 寿阳县| 安庆市|