`
xuela_net
  • 浏览: 495602 次
文章分类
社区版块
存档分类
最新评论

android一些不常用的事件

 
阅读更多

Android里有两个类

android.view.GestureDetector

android.view.GestureDetector.SimpleOnGestureListener (另外android.widget.Gallery好像是更牛x的OnGestureListener )

1)新建一个类继承SimpleOnGestureListener,HahaGestureDetectorListener 可以实现以下event事件。

boolean onDoubleTap(MotionEvent e) 解释:双击的第二下Touch down时触发

boolean onDoubleTapEvent(MotionEvent e) 解释:双击的第二下Touch down和up都会触发,可用e.getAction()区分。

boolean onDown(MotionEvent e) 解释:Touch down时触发

boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) 解释:Touch了滑动一点距离后,up时触发。

void onLongPress(MotionEvent e) 解释:Touch了不移动一直Touch down时触发

boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) 解释:Touch了滑动时触发。

void onShowPress(MotionEvent e) 解释:Touch了还没有滑动时触发 (与onDown,onLongPress比较 onDown只要Touch down一定立刻触发。 而Touchdown后过一会没有滑动先触发onShowPress再是onLongPress。 所以Touchdown后一直不滑动,onDown->onShowPress->onLongPress这个顺序触发。 )

boolean onSingleTapConfirmed(MotionEvent e) boolean onSingleTapUp(MotionEvent e) 解释:上面这两个函数都是在touch down后又没有滑动(onScroll),又没有长按(onLongPress),然后Touchup时触发。 点击一下非常快的(不滑动)Touchup: onDown->onSingleTapUp->onSingleTapConfirme


点击一下稍微慢点的(不滑动)Touchup: onDown->onShowPress->onSingleTapUp->onSingleTapConfirmed

2)在view的新建一个GestureDetector的对象。

构造函数里 gestureDetector = new GestureDetector(new HahaGestureDetectorListener());

然后在View的onTouchEvent里以下这样用,就可以在刚才1)弄的事件里写自己的代码了。

@Override public boolean onTouchEvent(MotionEvent event) { gestureDetector.onTouchEvent(event); }

但是,郁闷的是SimpleOnGestureListener没有提供onUp(), 还得在View的 onTouchEvent的 case MotionEvent.ACTION_UP: 里来写对应的代码。


分享到:
评论

相关推荐

    android Button监听事件的几种类型

    android Button常用监听事件的几种类型

    Android 常用六大框架

    目前支持常用的20种事件绑定,参见ViewCommonEventListener类和包com.lidroid.xutils.view.annotation.event。 (3) 网络模块:支持同步,异步方式的请求; 支持大文件上传,上传大文件不会oom; 支持GET,POST,...

    Android 按钮事件处理----Button

    常用Button类,初学者实用。 android:id="@+id/toggleButton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_close"/> android:id="@+id/...

    android常用控件属性方法事件说明.doc

    android常用控件属性方法事件说明

    android 编辑框事件处理----EditText

    常用输入编辑框,初学者实用。 android:id="@+id/editText01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/app1_edittext01"/> android:id="@+id/...

    Android一些常用功能的代码

    android一些核心功能程序代码 1、对话框 2、上下文菜单事件 3、选项菜单事件 4、创建上下文菜单 5、创建选项菜单 6、时间选择器 7、进度条 8、数据库绑定 10、发送短信程序 11:查看是否有存储卡插入 12:让某个...

    完全理解android事件分发机制

    但是源码的复杂往往会让新手产生畏惧难以理解,于是笔者最终还是打算使用实例log来让读者理解android事件分发。 #重要函数 笔者此次主要提及最常用的几个函数: (其间区别看源码很容易理解,此处直接给上结果) **...

    Android中TextView的常用效果实现

    android中TextView控件的一些常用效果:HTML设置样式、TextView点击事件,TextView跑马灯效果,TextView显示图片效果。

    Android Monkey测试常用命令.pdf

    Monkey是android sdk自带的一款命令行工具,适用于任何android模拟器或者真机。它通过向手机发送一系列的随机事件,来测试手机app的稳定性。

    Android onClick按钮单击事件的四种常用写法

    这里使用四种onClick单击事件,来实现电话拔号器的DEMO。 XML文件 <EditText android:layout_width=match_parent android:layout_height=wrap_content android:inputType=phone android:ems=10 android:id=...

    Android开发系列三之窗口的常用事件

    主要介绍了Android开发系列三之窗口的常用事件的相关资料,需要的朋友可以参考下

    android开发揭秘PDF

    4.2 常用控件应用 4.2.1 文本框(Textiew) 4.2.2 列表(ListView) 4.2.3 提示(T0ast) 4.2.4 编辑框(EditText) 4.2.5 单项选择(RadioGroup、RadioButton 4.2.6 多项选择(CheckBox) 4.2.7 下拉列表(Spinner) 4.2.8 自动...

    android处理键盘事件之物理按键(屏蔽后退键)

    本例子讲述了,android开发中常用的键盘事件的处理示例。另外,加有文档的说明

    Android应用开发详解

    Android开发基础,讲述了Android开发环境的搭建、Android常用工具的使用和第一个Android应用程序的开发 第二篇 技术篇 第3章 Android中的资源访问 Android 中的资源访问,讲述了如何定义和访问Android中的外部...

    Android事件分发与消费

    事件分发和消费我们主要涉及到以下三个方法:dispatchTouchEvent():分发事件onInterceptTouchEvent():拦截事件onTouchEvent():处理事件还需要注意常用的两个接口对以上方法的影响:OnClickListener:点击事件监听...

    在Unity中捕捉Android的常用按钮返回事件

    在Unity开发中捕捉Android的常用事件其实很简单,下面通过实例代码给大家详细介绍下,感兴趣的朋友一起看看吧

    疯狂Android讲义源代码2

    1.3 Android常用开发工具的用法 1.3.1 创建、删除和浏览AVD 1.3.2 使用Android模拟器(Emulator) 1.3.3 使用DDMS进行调试 1.3.4 Android Debug Bridge(ADB)的用法 1.3.5 使用DX编译Android应用 1.3.6 使用...

    android 常用的listview管理示例

    android 常用的listview管理示例。包括listview的里面数据的删除,点击,各种事件。较流行的一种写法,虽然界面比较丑,但具体是实现了。我的博客地址:http://blog.csdn.net/qq_16064871。

Global site tag (gtag.js) - Google Analytics