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);
    }
相关推荐
什巳3 小时前
JAVA练习278- 和为 K 的子数组
java·学习·算法·leetcode
豆瓣鸡3 小时前
RocketMQ学习-Spring Boot消息实践
java·spring boot·rocketmq
louisgeek3 小时前
Android Studio 和 Git
android
wuqingshun3141593 小时前
说一下mysql的覆盖索引
java
罗超驿4 小时前
2.算法效率的核心密码:时间复杂度和空间复杂度详解
java·数据结构·算法
栈溢出了4 小时前
Redis 分片集群与哈希槽笔记
java·redis·笔记·spring
遨游DATA4 小时前
Spring Boot 启动失败排查:如何区分多 Bean 冲突与清理阶段异常
java·spring boot·后端
wabs6665 小时前
关于单调栈【力扣739.每日温度的思考】
java·开发语言
雪碧聊技术5 小时前
为什么要学函数式编程?
java·函数式编程
爱吃提升5 小时前
Python桌面自动化PyAutoGUI完整实战教程:模拟鼠标键盘、窗口操作、图形识别自动化
python·自动化·计算机外设