歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android2.2.3 實現多點縮放功能

Android2.2.3 實現多點縮放功能:

  1. // 觸摸事件   
  2.     @Override  
  3.     public boolean onTouchEvent(MotionEvent event) {  
  4.         if (false == this.is_initialized()) {  
  5.             return false;  
  6.         }  
  7.   
  8.         try {  
  9.             PointF point_s = new PointF();  
  10.             point_s.x = event.getX();  
  11.             point_s.y = event.getY();  
  12.             int x = (int) point_s.x;// Float.to( event.getX() );   
  13.             int y = (int) point_s.y;// Float.floatToIntBits( event.getY() );   
  14.   
  15.             switch (event.getAction() & MotionEvent.ACTION_MASK) {  
  16.             case MotionEvent.ACTION_DOWN:  
  17.                 m_pressPt.set(x, y);  
  18.                 mode = DRAG;  
  19.                 break;  
  20.             case MotionEvent.ACTION_UP:  
  21.   
  22.                 if (mode == DRAG) {  
  23.                     int px = x - m_pressPt.x;  
  24.                     int py = y - m_pressPt.y;  
  25.   
  26.                     if (px != 0 && py != 0) {  
  27.                         m_naviEngine.SetCenter(480 - px, 270 - py);  
  28.                     }  
  29.                 }  
  30.   
  31.   
  32.                 mode = NONE;  
  33.   
  34.                 break;  
  35.                   
  36.             case MotionEvent.ACTION_POINTER_UP:  
  37.                 if (mode == ZOOM) {  
  38.                     float newDist = spacing(event);  
  39.                     if (newDist > 10f) {  
  40.                         float scale = newDist - oldDist;  
  41.                         if (scale > 0) {  
  42.                             m_levelIndex = getLevelIndex();  
  43.                             // 設置當前比例尺   
  44.                             if (m_levelIndex < m_level.length - 1) {  
  45.                                 m_levelIndex++;  
  46.                                 m_naviEngine.SetLevel(m_level[m_levelIndex]);  
  47.                                 m_btnZoomOut.setEnabled(true);  
  48.                                 if (m_levelIndex == m_level.length - 1) {  
  49.                                     m_btnZoomIn.setEnabled(false);  
  50.                                 }  
  51.   
  52.                                 // 更新信息彈出框   
  53.                                 // showPopSign();   
  54.                           
  55.                             }  
  56.                         } else {  
  57.                             m_levelIndex = getLevelIndex();  
  58.                             // 設置當前比例尺以及按鈕狀態   
  59.                             if (m_levelIndex > 0) {  
  60.                                 m_levelIndex--;  
  61.                                 m_naviEngine.SetLevel(m_level[m_levelIndex]);  
  62.                                 m_btnZoomIn.setEnabled(true);  
  63.                                 if (m_levelIndex == 0) {  
  64.                                     m_btnZoomOut.setEnabled(false);  
  65.                                 }  
  66.   
  67.                                 // 更新信息彈出框   
  68.                                 // showPopSign();   
  69.                             }  
  70.                         }  
  71.                     }  
  72.                 }  
  73.                 break;  
  74.             case MotionEvent.ACTION_POINTER_DOWN:  
  75.                 oldDist = spacing(event);  
  76.                 if (oldDist > 10f) {  
  77.   
  78.                     mode = ZOOM;  
  79.   
  80.                 }  
  81.                 break;  
  82.             }  
  83.         } catch (UnsatisfiedLinkError e) {  
  84.             return false;  
  85.         }  
  86.   
  87.         return m_gestureScanner.onTouchEvent(event);  
  88.     }  
Copyright © Linux教程網 All Rights Reserved