偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

淺談onInterceptTouchEvent、onTouchEvent與onTouch

移動開發(fā) Android
本文為Android開發(fā)詳解onInterceptTouchEvent函數實現(xiàn)分派各項功能的調用以實現(xiàn)各項任務。

一、onTouch

onTouch是View中OnTouchListener接口中的方法,處理View及其子類被touch是的事件處理。當然,前提是touch時間能夠傳遞到指定的view。Q1:為什么會傳遞不到呢?

  1.   /**     
  2.     * Interface definition for a callback to be invoked when a touch event is    
  3.      * dispatched to this view. The callback will be invoked before the touch     
  4.       * event is given to the view.     
  5.       */     
  6.      public interface OnTouchListener {     
  7.          /**     
  8.          * Called when a touch event is dispatched to a view. This allows listeners to    
  9.          * get a chance to respond before the target view.    
  10.          *    
  11.          * @param v The view the touch event has been dispatched to.    
  12.          * @param event The MotionEvent object containing full information about    
  13.          *        the event.    
  14.           * @return True if the listener has consumed the event, false otherwise.    
  15.          */    
  16.          boolean onTouch(View v, MotionEvent event);    
  17.     }  

二、onTouchEvent

onTouchEvent同樣也是在view中定義的一個方法。處理傳遞到view 的手勢事件。手勢事件類型包括ACTION_DOWN,ACTION_MOVE,ACTION_UP,ACTION_CANCEL四種事件。

  1. /**     
  2. * Implement this method to handle touch screen motion events.     
  3.  *     
  4.  * @param event The motion event.     
  5.  * @return True if the event was handled, false otherwise.     
  6.  */     
  7. public boolean onTouchEvent(MotionEvent event) {     
  8.  ……     
  9.  ……    

一旦onTouchEvent方法被調用,并返回true則這個手勢事件就結束了,并不會向下傳遞到子控件。Q2:onTouchEvent什么時候被調用呢?

三、onInterceptTouchEvent

onInterceptTouchEvent是在ViewGroup里面定義的。Android中的layout布局類一般都是繼承此類的。onInterceptTouchEvent是用于攔截手勢事件的,每個手勢事件都會先調用onInterceptTouchEvent。

  1.  
  2. public boolean onInterceptTouchEvent(MotionEvent ev) {     
  3.         return false;     
  4.  } 

此方法返回false,則手勢事件會向子控件傳遞;返回true,則調用onTouchEvent方法。

 原文鏈接:http://www.cnblogs.com/halzhang/archive/2010/08/18/1802611.html

【編輯推薦】

  1. 在Ubuntu下建立Eclipse的Android開發(fā)環(huán)境
  2. Intent,Android應用核心探秘
  3. Adobe AIR即將登陸Android平臺
責任編輯:張攀 來源: cnblogs
相關推薦

2012-12-21 09:48:06

JavaJavaSE異常

2012-12-21 10:15:35

2009-07-14 13:49:29

原型

2012-02-14 09:43:08

2013-01-08 15:11:19

OpenStackKVM

2009-03-11 15:30:05

evalwithJavascript

2011-04-18 00:00:00

SQLPLSQL

2018-02-23 14:44:41

負載均衡技術分類

2009-07-10 13:09:53

.Net與Java S

2011-02-16 09:48:04

Hashtable

2013-11-12 14:11:10

2009-06-26 16:09:53

2009-09-21 17:30:25

組件復用服務復用

2021-07-14 13:12:51

2010-09-13 14:34:55

2009-07-08 09:32:25

Java設計模式

2011-06-30 17:48:42

SEOSEM

2011-09-06 09:27:15

項目設計

2009-07-09 15:40:54

Java ServleCGI程序

2009-06-24 17:05:10

點贊
收藏

51CTO技術棧公眾號