Android添加触摸手势识别监听
2018-07-20 来源:open-open
import android.content.Context; import android.view.MotionEvent; import android.view.GestureDetector.SimpleOnGestureListener; import android.widget.Toast; public class MyGestureListener extends SimpleOnGestureListener { private Context mContext; MyGestureListener(Context context) { mContext = context; } @Override public boolean onDown(MotionEvent e) { Toast.makeText(mContext, "DOWN " + e.getAction(), Toast.LENGTH_SHORT).show(); return false; } @Override public void onShowPress(MotionEvent e) { Toast.makeText(mContext, "SHOW " + e.getAction(), Toast.LENGTH_SHORT).show(); } @Override public boolean onSingleTapUp(MotionEvent e) { Toast.makeText(mContext, "SINGLE UP " + e.getAction(), Toast.LENGTH_SHORT).show(); return false; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { Toast.makeText(mContext, "SCROLL " + e2.getAction(), Toast.LENGTH_SHORT).show(); return false; } @Override public void onLongPress(MotionEvent e) { Toast.makeText(mContext, "LONG " + e.getAction(), Toast.LENGTH_SHORT).show(); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { Toast.makeText(mContext, "FLING " + e2.getAction(), Toast.LENGTH_SHORT).show(); return false; } @Override public boolean onDoubleTap(MotionEvent e) { Toast.makeText(mContext, "DOUBLE " + e.getAction(), Toast.LENGTH_SHORT).show(); return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { Toast.makeText(mContext, "DOUBLE EVENT " + e.getAction(), Toast.LENGTH_SHORT).show(); return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { Toast.makeText(mContext, "SINGLE CONF " + e.getAction(), Toast.LENGTH_SHORT).show(); return false; } } package noodies.blog.csdn.net; import android.app.Activity; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; public class GestureTestActivity extends Activity { private GestureDetector mGestureDetector; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mGestureDetector = new GestureDetector(this, new MyGestureListener(this)); } @Override public boolean onTouchEvent(MotionEvent event) { return mGestureDetector.onTouchEvent(event); } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐