android鼠标滚轮事件监听方法

复制代码
@Override
    public 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) {
                        LogUtils.d("fortest::onGenericMotionEvent down");
                       
                    }
                    //获得垂直坐标上的滚动方向,也就是滚轮向上滚
                    else {
                        LogUtils.i("fortest::onGenericMotionEvent up");
                        
                    }
                    
                    return true;
            }
        }
        return super.onGenericMotionEvent(event);
    }
相关推荐
萧曵 丶5 分钟前
JDK各版本新增特性详解
java·面试
TeleostNaCl6 分钟前
Android | 启用 TextView 跑马灯效果的方法
android·经验分享·android runtime
毅炼29 分钟前
hot100打卡——day08
java·数据结构·算法·leetcode·深度优先
a努力。38 分钟前
国家电网Java面试被问:慢查询的优化方案
java·开发语言·面试
@小码农1 小时前
202512 电子学会 Scratch图形化编程等级考试四级真题(附答案)
java·开发语言·算法
TheNextByte11 小时前
Android USB文件传输无法使用?5种解决方法
android
程序猿ZhangSir1 小时前
深入理解 BIO,NIO,AIO 三者的用途和区别?Select,poll,epoll 操作系统函数简介
java·spring·nio
智航GIS1 小时前
6.2 while循环
java·前端·python
2201_757830871 小时前
AOP核心概念
java·前端·数据库
为所欲为、Lynn1 小时前
用FastJson的Filter自动映射枚举
java·spring boot