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);
    }
相关推荐
hai_android13 小时前
SendChannel 与 ReceiveChannel 通信机制
android
garmin Chen13 小时前
redis面试题
java·数据库·redis·缓存
chen<>13 小时前
C++ 六种 memory_order:从原子性到线程间可见性.md
java·linux·开发语言·c++
十年Java程序媛13 小时前
SpringBoot3 + JDK17 实战复盘:HikariCP 连接耗尽,虚拟线程场景额外注意事项
java·spring boot
二十雨辰14 小时前
[Java]-JVM面试题
java·开发语言·jvm
cfm_291414 小时前
ConcurrentHashMap 线程安全机制与 JDK 1.8 演进
java·开发语言·安全
tqs_1234514 小时前
值传递与引用传递
java·开发语言·python
2601_9621819614 小时前
Spring boot从0到1 - day01
java·spring boot·后端
数据治理自习室14 小时前
AI 应用评测体系(GraphRAG)
android·大数据·人工智能·kotlin
典典分享指南14 小时前
短视频分镜提示词:让 AI 出片的产品口播
java·c#·bash·composer·symfony