How can my view respond to a mousewheel?

后端 未结 2 1319
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 06:24

I have a view with an onTouch that can distinguish between touch input and left/middle/right mouse clicks, as in

@Override
public boolean onTouc         


        
相关标签:
2条回答
  • 2020-12-31 06:40

    The accepted answer was a document link that led me to the example code in the question, but that answer was deleted. So that this question no longer appears 'unanswered', this is how your view can respond to a mousewheel:

    @Override
    public boolean onGenericMotionEvent(MotionEvent event) {
      if (0 != (event.getSource() & InputDevice.SOURCE_CLASS_POINTER)) {
        switch (event.getAction()) {
          case MotionEvent.ACTION_SCROLL:
            if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f)
              selectNext();
            else
              selectPrev();
            return true;
        }
      }
      return super.onGenericMotionEvent(event);
    }
    
    0 讨论(0)
  • 2020-12-31 06:48

    The mouse wheel event action is considered a scroll event

    0 讨论(0)
提交回复
热议问题