android鼠标滚轮事件坐标,android 处理鼠标滚轮事件 【转】
android處理鼠標(biāo)滾輪事件,并不是如下函數(shù):
1) ?public boolean onKeyDown(int keyCode, KeyEvent event)
2) ? ??public boolean dispatchKeyEvent(KeyEvent event)
3) ? ??public boolean onTouchEvent(MotionEvent event)
而是如下函數(shù)
publicboolean onGenericMotionEvent(MotionEvent event);
所有View和Activity都可重寫該函數(shù),來自己處理滾輪事件,
如下代碼:
/**
* Implement this method to handle generic motion events.
* 實現(xiàn)該方法來處理一般的MotionEvent;
* 一般的motion events 描述,操縱桿的動作,鼠標(biāo)honver、滾輪等
*
* @param event The generic motion event being processed.
* @return True if the event was handled, false otherwise.
*/
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
//The input source is a pointing device associated with a display.
//輸入源為可顯示的指針設(shè)備,如:mouse pointing device(鼠標(biāo)指針),stylus pointing device(尖筆設(shè)備)
if (0 != (event.getSource() & InputDevice.SOURCE_CLASS_POINTER)) {
switch (event.getAction()) {
// process the scroll wheel movement...處理滾輪事件
case MotionEvent.ACTION_SCROLL:
//獲得垂直坐標(biāo)上的滾動方向,也就是滾輪向下滾
if( event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f){
Log.i("fortest::onGenericMotionEvent", "down" );
}
//獲得垂直坐標(biāo)上的滾動方向,也就是滾輪向上滾
else{
Log.i("fortest::onGenericMotionEvent", "up" );
}
return true;
}
}
return super.onGenericMotionEvent(event);
}
轉(zhuǎn)載請注明出處,jiese1990
原文:http://www.cnblogs.com/luob/p/4757421.html
總結(jié)
以上是生活随笔為你收集整理的android鼠标滚轮事件坐标,android 处理鼠标滚轮事件 【转】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android倒计时功能,Android
- 下一篇: android 缓存文件的工具类,总结的