亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

android使用gesturedetector手勢(shì)識(shí)別示例分享

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

復(fù)制代碼 代碼如下:

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

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

 

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

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

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

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

}

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

// 抬起,手指離開(kāi)觸摸屏?xí)r觸發(fā)(長(zhǎng)按、滾動(dòng)、滑動(dòng)時(shí),不會(huì)觸發(fā)這個(gè)手勢(shì))
/*@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;//手勢(shì)對(duì)象
private MyGestureLintener myGestureLintener;//手勢(shì)監(jiān)聽(tīng)的接口對(duì)象

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

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

/**GestureDetector類(lèi)的onTouchEvent方法用來(lái)辨別不同的手勢(shì)*/
@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)文章

最新評(píng)論