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);
    }
相关推荐
程序员码歌4 分钟前
短思考第268天,自媒体路上的4大坑点,很多人都踩过
android·前端·ai编程
zs宝来了16 分钟前
ArrayList源码阅读
java
brave_zhao33 分钟前
关于javafx下打开postman无法正常关闭postman的问题
java·测试工具·postman
攻心的子乐36 分钟前
Spring IOC 源码
java·后端·spring
Sirens.37 分钟前
Java异常处理解析:从防御式编程到自定义异常类
java·开发语言·笔记·学习·github·javac
千寻技术帮1 小时前
10351_基于Springboot的二手交易平台
java·spring boot·mysql·毕业设计·源码·代码·二手交易
alonewolf_991 小时前
Spring依赖注入源码深度解析:从@Autowired到@Resource的完整实现机制
java·后端·spring
雪碧聊技术1 小时前
如何界定人工智能和java开发二者的关系?
java·人工智能·二者关系界定
Chase_______1 小时前
【JAVA基础指南(四)】快速掌握类和对象
java·开发语言
消失的旧时光-19431 小时前
从 Android 组件化到 Flutter 组件化
android·flutter·架构