zoukankan      html  css  js  c++  java
  • android屏幕监控上下左右滑动

    简单写一下,view 或者 activity 实现 OnGestureListener 接口。

    在 onFling方法中实现左右滑动:


    [java] view plaincopy
    1. public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,  
    2.             float distanceY) {  
    3.         float y1 = e1.getY(), y2 = e2.getY();  
    4.         if (y1 -y2 > 120) {    
    5.             if (mDirection != SOUTH) {  
    6.                 mNextDirection = NORTH;  
    7.             }  
    8.             Log.d(this.getClass().getName(), "To UP" + "(" + y1  
    9.                     + "," + y2 + ")");  
    10.             return (true);  
    11.         } else if (y1 - y2 < -120) {    
    12.             if (mDirection != NORTH) {  
    13.                 mNextDirection = SOUTH;  
    14.             }  
    15.             Log.d(this.getClass().getName(), "To Down" + "(" + y1  
    16.                     + "," + y2 + ")");  
    17.             return (true);  
    18.         }    
    19.         return false;  
    20.     }  

    在 onScroll 方法中实现上下滑动:

    [java] view plaincopy
    1. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,  
    2.             float velocityY) {  
    3.         Log.d("Fling""Fling Happened!");    
    4.         float x1 = e1.getX(), x2 = e2.getX();  
    5.           
    6.         if (x1 -x2 > 120) {    
    7.             if (mDirection != EAST) {  
    8.                 mNextDirection = WEST;  
    9.             }  
    10.             Log.d(this.getClass().getName(), "To LEFT" + "(" + x1  
    11.                     + "," + x2 + ")");  
    12.             return (true);  
    13.         } else if (x1 - x2 < -120) {    
    14.             if (mDirection != WEST) {  
    15.                 mNextDirection = EAST;  
    16.             }  
    17.             Log.d(this.getClass().getName(), "To Right" + "(" + x1  
    18.                     + "," + x2 + ")");  
    19.             return (true);  
    20.         }    
    21.           
    22.         return false;  
    23.     }  
  • 相关阅读:
    转载 NPOI.dll 用法。单元格,样式,字体,颜色,行高,宽度。读写excel
    Microsoft Visual SourceSafe 6.0 无法关联项目
    dynamic json
    c#查找string数组的某一个值的索引
    C#中 删除掉字符串数组中的空字符串
    c# 比较两个数组每一个值是否相等
    c#比较两个数组的差异
    C#动态操作DataTable(新增行、列、查询行、列等)
    C#数字转字母,ASCII码转换
    c#中使程序跳到指定行中
  • 原文地址:https://www.cnblogs.com/weinyzhou/p/4983415.html
Copyright © 2011-2022 走看看