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);
    }
相关推荐
你不是我我6 小时前
【Java 开发日记】HTTP3 性能更好,为什么内网微服务依然多用 HTTP2?HTTP2 内网优势是什么?
java·开发语言·微服务
雪碧聊技术6 小时前
大模型爆火!Java后端如何抓住Agent全栈开发的风口
java·大模型·agent·全栈开发
赏金术士6 小时前
Kotlin 数据流与单双向绑定
android·开发语言·kotlin
逻辑驱动的ken7 小时前
Java高频面试场景题25
java·开发语言·深度学习·面试·职场和发展
小白学鸿蒙8 小时前
Unity 3D 2023解压安装,配置安卓运行环境后打包安卓应用(踩坑无数之差点放弃)
android·unity·游戏引擎
AI人工智能+电脑小能手8 小时前
【大白话说Java面试题】【Java基础篇】第32题:Java的异常处理机制是什么
java·开发语言·后端·面试
阿巴斯甜8 小时前
2026小知识点(9)
android
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ9 小时前
通过java后端代码来实现给word内容补充格式文本内容控件,以及 设置控件的标记和标题
java·c#·word
古月-一个C++方向的小白10 小时前
MySQL数据库——数据类型
android·数据库·mysql