zoukankan      html  css  js  c++  java
  • 多点触摸技术

     1 //多点触摸  放大,缩小
     2 public class MainActivity extends ActionBarActivity {
     3 
     4     @Override
     5     protected void onCreate(Bundle savedInstanceState) {
     6         super.onCreate(savedInstanceState);
     7         setContentView(R.layout.fragment_main);
     8 
     9     }
    10 
    11     @Override
    12     public boolean onTouchEvent(MotionEvent event) {
    13         // TODO Auto-generated method stub
    14         // 两点触摸
    15         if (event.getPointerCount() == 2) {
    16             if (event.getAction() == MotionEvent.ACTION_MOVE) {
    17                 int historySize = event.getHistorySize();
    18                 if (historySize == 0) {
    19                     return true;
    20                 }
    21                 // 获取第一个手指当前的纵坐标
    22                 float currentY1 = event.getY(0);
    23                 // 获取第一个手指当前最新的历史的纵坐标
    24                 float historyY1 = event.getHistoricalY(0, historySize - 1);
    25                 // 获取第二个手指当前的纵坐标
    26                 float currentY2 = event.getY(2);
    27                 // 获取第二个手指当前最新的历史的纵坐标
    28                 float historyY2 = event.getHistoricalY(1, historySize - 1);
    29                 // 两手指当前纵坐标的距离
    30                 float distance = Math.abs(currentY1 - currentY2);
    31                 // 两手指最新的历史纵坐标的距离
    32                 float historyDistance = Math.abs(historyY1 - historyY2);
    33 
    34                 if (distance > historyDistance) {
    35                     Log.i("-====>", "放大");
    36                 } else if (distance < historyDistance) {
    37                     Log.i("-====>", "缩小");
    38                 } else {
    39                     Log.i("-====>", "移动");
    40                 }
    41             }
    42         }
    43         return super.onTouchEvent(event);
    44     }
    45 
    46 }
  • 相关阅读:
    CF526D Om Nom and Necklace
    POJ2406 Power Strings
    POJ3461 Oulipo
    luogu P1341 无序字母对
    UOJ 117 欧拉回路
    骑马修栅栏
    vimdiff env.txt export.txt set.txt
    Linux自动执行任务
    消灭 Bug!推荐5款测试员不可不知的bug管理工具!
    Bugzilla使用手册及解决方案
  • 原文地址:https://www.cnblogs.com/my334420/p/6924586.html
Copyright © 2011-2022 走看看