// 單擊,觸摸屏按下時(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),過一段時(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;
}*/
// 抬起,手指離開觸摸屏?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)聽的接口對(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類的onTouchEvent方法用來辨別不同的手勢(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;
}
}
新聞熱點(diǎn)
疑難解答
圖片精選