android处理鼠标滚轮事件,并不是如下函数

1) public boolean onKeyDown(int keyCode, KeyEvent event)

2) public boolean dispatchKeyEvent(KeyEvent event)

3) public boolean onTouchEvent(MotionEvent event)


是如下函数

publicboolean onGenericMotionEvent(MotionEvent event);


所有View和Activity都可重写该函数,来自己处理滚轮事件,

如下代码:


/*** Implement this method to handle generic motion events.* 实现该方法来处理一般的MotionEvent;* 一般的motion events 描述,操纵杆的动作,鼠标honver、滚轮等* * @param event The generic motion event being processed.* @return True if the event was handled, false otherwise. */@Overridepublic boolean onGenericMotionEvent(MotionEvent event) {//The input source is a pointing device associated with a display.//输入源为可显示的指针设备,如:mouse pointing device(鼠标指针),stylus pointing device(尖笔设备)if (0 != (event.getSource() & InputDevice.SOURCE_CLASS_POINTER)) {  switch (event.getAction()) {// process the scroll wheel movement...处理滚轮事件case MotionEvent.ACTION_SCROLL://获得垂直坐标上的滚动方向,也就是滚轮向下滚if( event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f){Log.i("fortest::onGenericMotionEvent", "down" );}//获得垂直坐标上的滚动方向,也就是滚轮向上滚else{Log.i("fortest::onGenericMotionEvent", "up" );}return true;}}return super.onGenericMotionEvent(event);}


转载请注明出处,jiese1990。

更多相关文章

  1. C语言函数以及函数的使用
  2. android 回调函数二:应用实例
  3. android NDK JNI设置自己的log输出函数
  4. Android build/envsetup.sh 脚本分析(lunch函数)
  5. Android Hook学习之ptrace函数的使用
  6. Android中回调函数的理解---本人Android纯新手
  7. 【Android NDK 开发】Ubuntu 函数库交叉编译 ( Android 动态库交
  8. Android学习札记12:对Parcelable中describeContents()函数的一种
  9. android常用函数参数补充

随机推荐

  1. android 关于程序升级问题
  2. android发送邮件
  3. android 之 广播相关
  4. Android(安卓)ApiDemos示例解析(9):App->A
  5. Android(安卓)Framework内核之旅
  6. android加载字体内存泄漏的处理方法
  7. Android(安卓)Studio 3.0找不到Android(
  8. [GoogleMap/GPS] 申请Android(安卓)API K
  9. android中的spannable的使用
  10. Android编译异常之Process 'command 'D: