android 手势操作GestureDetector
来源:学习笔记 责任编辑:栏目编辑 发表时间:2013-07-01 18:58 点击:次
利用触摸屏的Fling、Scroll等Gesture(手势)操作来操作会使得应用程序的用户体验大大提升,比如用Scroll手势在 浏览器中滚屏,用Fling在阅读器中翻页等。在Android系统中,手势的识别是通过 GestureDetector.OnGestureListener接口来实现的,举例说明:
- public class ActivityMain extends Activity implements GestureDetector.OnGestureListener {
- GestureDetector detector;
- /**
- * Called when the activity is first created.
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- //构造GestureDetector;Context context, OnGestureListener listener
- detector = new GestureDetector(this, this);
- detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
- //短快的点击算一次单击
- @Override
- public boolean onSingleTapConfirmed(MotionEvent e) {
- System.out.println("onSingleTapConfirmed");
- return false;
- }
- //双击时产生一次
- @Override
- public boolean onDoubleTap(MotionEvent e) {
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>