android 處理鼠標滾輪事件 【轉】

android處理鼠標滾輪事件,并不是如下函數:

?

1) ?public boolean onKeyDown(int keyCode, KeyEvent event) ?

2) ? ??public boolean dispatchKeyEvent(KeyEvent event)?

3) ? ??public boolean onTouchEvent(MotionEvent event)

?

而是如下函數

?

publicboolean onGenericMotionEvent(MotionEvent event);

?

所有View和Activity都可重寫該函數,來自己處理滾輪事件,

如下代碼:

/**
* Implement this method to handle generic motion events.
* 實現該方法來處理一般的MotionEvent;
* 一般的motion events 描述,操縱桿的動作,鼠標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.
//輸入源為可顯示的指針設備,如: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){
Log.i("fortest::onGenericMotionEvent", "down" );
}
//獲得垂直坐標上的滾動方向,也就是滾輪向上滾
else{
Log.i("fortest::onGenericMotionEvent", "up" );
}
return true;
}
}
return super.onGenericMotionEvent(event);
}

轉載請注明出處,jiese1990

轉載于:https://www.cnblogs.com/luob/p/4757421.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/375603.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/375603.shtml
英文地址,請注明出處:http://en.pswp.cn/news/375603.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ASP.NET數據報表之柱狀圖 ------工作日志

#region 柱形色調 /// <summary> /// 柱形色調 /// </summary> private string[] myColor new string[] { "DarkGreen", "DimGray", "DodgerBlue", "Orchid", //Peru "Orange", "Orchid", &q…

接口安全--簽名驗證

為防止第三方冒充客戶端請求服務器&#xff0c;可以采用參數簽名驗證的方法&#xff1a; 將請求參數中的各個鍵值對按照key的字符串順序升序排列&#xff08;大小寫敏感&#xff09;&#xff0c;把key和value拼成一串之后最后加上密鑰&#xff0c;組成key1value1key2value2PRIV…

Runtime類

Runtime類也在java.lang包中&#xff0c;這個類沒有提供構造器&#xff0c;但是提供的卻非靜態方法&#xff0c;而是在方法中提供了一個靜態方法來返回當前進程的Runtime實例&#xff0c;采用的單例設計模式。 其作用&#xff1a;可以對當前java程序進程進行操作、打開本機程序…

Spring MVC 返回NULL時客戶端用$.getJSON的問題

如果Spring MVC返回是NULL&#xff0c;那么客戶端的$.getJSON就不會觸發&#xff1b; 20170419補充 后臺的輸出為&#xff1a; DEBUG [org.springframework.web.servlet.DispatcherServlet] - Null ModelAndView returned to DispatcherServlet with name springMVC: assuming …

duilib設置滾動條自動滾動到底

控件屬性中添加 vscrollbar"true" autovscroll"true"分別是啟用豎向滾動條&#xff0c;是否隨輸入豎向滾動

MVC,MVP 和 MVVM 的圖示

復雜的軟件必須有清晰合理的架構&#xff0c;否則無法開發和維護。 MVC&#xff08;Model-View-Controller&#xff09;是最常見的軟件架構之一&#xff0c;業界有著廣泛應用。它本身很容易理解&#xff0c;但是要講清楚&#xff0c;它與衍生的 MVP 和 MVVM 架構的區別就不容易…

Java JDBC學習實戰(二): 管理結果集

在我的上一篇博客《Java JDBC學習實戰&#xff08;一&#xff09;&#xff1a; JDBC的基本操作》中&#xff0c;簡要介紹了jdbc開發的基本流程&#xff0c;并詳細介紹了Statement和PreparedStatement的使用&#xff1a;利用這兩個API可以執行SQL語句&#xff0c;完成基本的CURD…

error: storage size of ‘threads’ isn’t known

出錯的代碼行&#xff1a; pthread_t threads[NUM_THREADS];原因&#xff1a; NUM_THREADS 無值 原先&#xff1a; #define NUM_THREADS修改為 #define NUM_THREADS 5

android之相機開發

http://blog.csdn.net/jason0539/article/details/10125017 android之相機開發 分類&#xff1a; android 基礎知識2013-08-20 22:32 9774人閱讀 評論(2) 收藏 舉報Android在android中應用相機功能&#xff0c;一般有兩種&#xff1a;一種是直接調用系統相機&#xff0c;一種自…

文件和文件夾權限-Win7公共盤中出現大量臨時文件

公司中有一個文件服務器&#xff0c;給不同部門和員工設置了不同的權限&#xff0c;最近有員工&#xff08;沒有修改權限&#xff0c;有讀取及執行,讀取,寫入&#xff09;反映在公共盤上修改文件的時候會產生大量的臨時文件&#xff0c;添加上修改權限之后就可以了&#xff0c;…

Duilib編輯框Edit輸入完自動跳到下一個編輯框

首先xml文件中設置edit的maxchar參數&#xff0c;默認255好像。 <edit maxchar"10" />然后在notify函數中加入以下代碼 if (msg.sType _T("textchanged")) {if (static_cast<CEditUI*>(msg.pSender)->GetMaxChar() msg.pSender->GetT…

Mysql數據庫安全管理配置

1.刪除test庫 原因&#xff1a; The default MySQL installation comes with a database named test that anyone can access. This database is intended only for tutorials, samples, testing, etc. Databases named "test" and also databases with names starti…

duilib清空richedit內容

推薦使用以下方法&#xff1a; m_pRichEdit->SetSelAll(); m_pRichEdit->Clear();不推薦使用以下方法&#xff1a; m_pRichEdit->SetText("");雖然效果是一樣的&#xff0c;但是當編輯框中文本存在多種格式的時候&#xff0c;第二種方法會存在問題&#x…

新學了一個用python編寫的簡單的百度貼吧帖子的爬蟲

# -*- coding: utf-8 -*- #--------------------------------------- # 作者&#xff1a;chendn # 語言&#xff1a;Python 2.7.10 #---------------------------------------import string,urllib2 def tieba(url,beginPage,endPage):for i in range(beginPage,endPage1):…

duilib自定義消息

/** NOTE: All Message Numbers below 0x0400 are RESERVED.** Private Window Messages Start Here:*/ #define WM_USER 0x0400從WM_USER往上加就行了

BZOJ 2190儀仗隊【歐拉函數】

問題的唯一難點就是如何表示隊長能看到的人數&#xff1f;如果建系&#xff0c;隊長所在的點為&#xff08;0,0&#xff09;分析幾組數據就一目了然了&#xff0c;如果隊長能看到的點為(m,n),那么gcd&#xff08;m&#xff0c;n&#xff09;1即m n 互質或者是&#xff08;0,1&a…

Codeforces Round #318 (Div. 2) B Bear and Three Musketeers (暴力)

算一下復雜度。發現可以直接暴。對于u枚舉a和b&#xff0c;判斷一下是否連邊&#xff0c;更新答案。 #include<bits/stdc.h> using namespace std;int n,m; const int maxn 4001; #define PB push_back vector<int> G[maxn]; bool g[maxn][maxn]; int deg[maxn]; …

form表單,submit,ajax提交

尼瑪... 一個簡單的表單提交&#xff0c;竟然給我整的直郁悶。 本來就是個保存功能&#xff0c;幾個前人都用的ajax提交&#xff0c;我也就沒改成submit。然后坑爹的就來了。 我在表單里寫了個<form></form>&#xff08;實際用ajax提交&#xff0c;也沒必要寫這個標…

windows 文件對話框

https://docs.microsoft.com/zh-cn/previous-versions/windows/desktop/legacy/bb776913(vvs.85)