【安卓笔记】GestureDetector浅析
package com.example.gesturedetectordemo; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.View; import android.view.View.OnTouchListener; import android.view.MotionEvent; /** * @author Rowand jj * *GestureDetector的使用步骤: * 1.创建GestureDetector实例 * 2.复写view类的onTouchEvent,调用GestureDetector的onTouchEvent */ public class MainActivity extends Activity implements OnGestureListener { private static final String TAG = "MainActivity"; private GestureDetector mGestureDector = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGestureDector = new GestureDetector(this,this); } @Override public boolean onTouchEvent(MotionEvent event) { //监听手势事件 return mGestureDector.onTouchEvent(event); } @Override public boolean onDown(MotionEvent e) { Log.i(TAG,"onDown run.."); return false; } @Override public void onShowPress(MotionEvent e) { Log.i(TAG,"onShowPress run.."); } @Override public boolean onSingleTapUp(MotionEvent e) { Log.i(TAG,"onSingleTapUp run.."); return false; } @Override// 用户按下触摸屏,并拖动 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { Log.i(TAG,"onScroll run.."); return false; } @Override public void onLongPress(MotionEvent e) { Log.i(TAG,"onLongPress run.."); } //用户按下触摸屏、快速移动后松开 @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { Log.i(TAG,"onFling run.."); return false; } }
点击屏幕不松手:
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。