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);
    }
相关推荐
摇滚侠2 分钟前
Maven 入门+高深 SSM 案例 111-112
java·数据库·maven
DS随心转插件4 分钟前
DeepSeek 代码手机端导出与 AI 辅助方案实测
android·人工智能·chatgpt·智能手机·deepseek·ai导出鸭
Chase_______6 分钟前
【Java基础 | 16】集合框架(下):Map、HashMap 与 TreeMap
java·windows
Aaswk13 分钟前
Java项目:文件批量处理工具
java·开发语言·vscode·idea
JohnnyDeng9417 分钟前
【Android】Flow vs LiveData:选型指南与迁移实践
android·kotlin·livedata·flow
小江的记录本17 分钟前
【Spring全家桶】Spring AI核心原理、大模型集成、Prompt工程、RAG实现、AI Agent开发(附《思维导图》+《面试高频考点清单》)
java·人工智能·spring boot·后端·spring·面试·prompt
plainGeekDev21 分钟前
线程安全集合 → 协程安全替代
android·java·kotlin
zhangphil22 分钟前
Kotlin管道Channel构造函数参数capacity值RENDEZVOUS与UNLIMITED
android·kotlin
道法自然,人法天26 分钟前
屏幕卡死无法点击?只用键盘重启电脑
计算机外设·电脑
手握风云-27 分钟前
Spring AI:让大模型住进 Spring 生态(五)
java·后端·spring