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);
    }
相关推荐
三8443 分钟前
Java 模板注入(FreeMarker) · 02 · 模板引擎与 FreeMarker 语法
java·开发语言·web安全·freemarker
暮雨哀尘28 分钟前
Java 基础练习(一):创建类并调用对象
java·开发语言
想要入门的程序猿1 小时前
回调函数学习
java·网络·学习
泡海椒1 小时前
动态代理核心原理:JQuick-Java接口规则自动生成机制解析
java·开发语言·python
步行cgn1 小时前
Spring 启动报错:BeanFactory not initialized 的原因与解决
java·python·spring
步行cgn1 小时前
Spring 报错:No bean class specified on bean definition 的原因与解决
java·后端·spring
光电的一只菜鸡2 小时前
为什么调整LSC会对AF产生影响
android·开发语言·kotlin
zhangjw342 小时前
第47篇:Java综合实战:电商秒杀系统(高并发场景)
java·开发语言
凛_Lin~~2 小时前
LiveData 源码解析
android·安卓·livedata
土司大王2 小时前
LeetCode hot100 回溯专题总结:Java 通用模板、决策树模型
java·算法·leetcode·决策树