码迷,mamicode.com
首页 > 移动开发 > 详细

安卓手势

时间:2016-05-04 22:43:40      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

//在屏幕划过时触发该方法

onFling(MotionEvent event1, MotionEvent event2,
            float velocityX, float velocityY)

    velocityX = velocityX > 4000 ? 4000 : velocityX;
        velocityX = velocityX < -4000 ? -4000 : velocityX;
      
 // 根据手势的速度来计算缩放比,如果velocityX>0,放大图像,否则缩小图像。
        currentScale += currentScale * velocityX / 4000.0f;
      
 // 保证currentScale不会等于0
        currentScale = currentScale > 0.01 ? currentScale : 0.01f;
      
 // 重置Matrix
        matrix.reset();
        
// 缩放Matrix
        matrix.setScale(currentScale, currentScale, 160, 200);
        BitmapDrawable tmp =
                (BitmapDrawable) imageView.getDrawable();
      
 // 如果图片还未回收,先强制回收该图片
        if (!tmp.getBitmap().isRecycled()) // ①
        {
            tmp.getBitmap().recycle();
        }
     
   // 根据原始位图和Matrix创建新图片
        Bitmap bitmap2 = Bitmap.createBitmap
                (bitmap, 0, 0, width, height,matrix, true);
      
 // 显示新的位图
        imageView.setImageBitmap(bitmap2);
        return true;
    }

//    e1: The first down motion event that started the fling.
//    手势起点的移动事件
//    e2: The move motion event that triggered the current onFling.
//    当前手势点的移动事件
//    velocityX: The velocity of this fling measured in pixels per second along the x axis.
//    每秒x轴方向移动的像素
//    velocityY: The velocity of this fling measured in pixels per second along the y axis.
//    每秒y轴方向移动的像素
//    
//    说的更简单点就是,鼠标手势相当于一个向量(当然有可能手势是曲线),
//    e1为向量的起点,e2为向量的终点,
//    velocityX为向量水平方向的速度,velocityY为向量垂直方向的速度

//触碰时触发

public boolean onDown(MotionEvent arg0) {    }

//长按时可触发

public void onLongPress(MotionEvent event) {
    }

//在屏幕上滚动时可以触发,滚动相对于滑动速度较慢

public boolean onScroll(MotionEvent event1, MotionEvent event2,
            float distanceX, float distanceY) {
    }

//在屏幕上按而没有离开移动时触发

public void onShowPress(MotionEvent event) {
    }

//轻击时触发该方法

public boolean onSingleTapUp(MotionEvent event) {
      
    }

安卓手势

标签:

原文地址:http://www.cnblogs.com/red-tomato/p/5459757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!