zoukankan      html  css  js  c++  java
  • Android多点触控技术实战,自由地对图片进行缩放和移动

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/11100327

    在上一篇文章中我带着大家一起实现了Android瀑布流照片墙的效果,虽然这种效果很炫很酷,但其实还只能算是一个半成品,因为照片墙中所有的图片都是只能看不能点的。因此本篇文章中,我们就来对这一功能进行完善,加入点击图片就能浏览大图的功能,并且在浏览大图的时候还可以通过多点触控的方式对图片进行缩放。

    如果你还没有看过 Android瀑布流照片墙实现,体验不规则排列的美感 这篇文章,请尽量先去阅读完再来看本篇文章,因为这次的代码完全是在上次的基础上进行开发的。

    那我们现在就开始动手吧,首先打开上次的PhotoWallFallsDemo项目,在里面加入一个ZoomImageView类,这个类就是用于进行大图展示和多点触控缩放的,代码如下所示:

    [java] view plaincopy

    1. public class ZoomImageView extends View {  
    2.   
    3.     /** 
    4.      * 初始化状态常量 
    5.      */  
    6.     public static final int STATUS_INIT = 1;  
    7.   
    8.     /** 
    9.      * 图片放大状态常量 
    10.      */  
    11.     public static final int STATUS_ZOOM_OUT = 2;  
    12.   
    13.     /** 
    14.      * 图片缩小状态常量 
    15.      */  
    16.     public static final int STATUS_ZOOM_IN = 3;  
    17.   
    18.     /** 
    19.      * 图片拖动状态常量 
    20.      */  
    21.     public static final int STATUS_MOVE = 4;  
    22.   
    23.     /** 
    24.      * 用于对图片进行移动和缩放变换的矩阵 
    25.      */  
    26.     private Matrix matrix = new Matrix();  
    27.   
    28.     /** 
    29.      * 待展示的Bitmap对象 
    30.      */  
    31.     private Bitmap sourceBitmap;  
    32.   
    33.     /** 
    34.      * 记录当前操作的状态,可选值为STATUS_INIT、STATUS_ZOOM_OUT、STATUS_ZOOM_IN和STATUS_MOVE 
    35.      */  
    36.     private int currentStatus;  
    37.   
    38.     /** 
    39.      * ZoomImageView控件的宽度 
    40.      */  
    41.     private int width;  
    42.   
    43.     /** 
    44.      * ZoomImageView控件的高度 
    45.      */  
    46.     private int height;  
    47.   
    48.     /** 
    49.      * 记录两指同时放在屏幕上时,中心点的横坐标值 
    50.      */  
    51.     private float centerPointX;  
    52.   
    53.     /** 
    54.      * 记录两指同时放在屏幕上时,中心点的纵坐标值 
    55.      */  
    56.     private float centerPointY;  
    57.   
    58.     /** 
    59.      * 记录当前图片的宽度,图片被缩放时,这个值会一起变动 
    60.      */  
    61.     private float currentBitmapWidth;  
    62.   
    63.     /** 
    64.      * 记录当前图片的高度,图片被缩放时,这个值会一起变动 
    65.      */  
    66.     private float currentBitmapHeight;  
    67.   
    68.     /** 
    69.      * 记录上次手指移动时的横坐标 
    70.      */  
    71.     private float lastXMove = -1;  
    72.   
    73.     /** 
    74.      * 记录上次手指移动时的纵坐标 
    75.      */  
    76.     private float lastYMove = -1;  
    77.   
    78.     /** 
    79.      * 记录手指在横坐标方向上的移动距离 
    80.      */  
    81.     private float movedDistanceX;  
    82.   
    83.     /** 
    84.      * 记录手指在纵坐标方向上的移动距离 
    85.      */  
    86.     private float movedDistanceY;  
    87.   
    88.     /** 
    89.      * 记录图片在矩阵上的横向偏移值 
    90.      */  
    91.     private float totalTranslateX;  
    92.   
    93.     /** 
    94.      * 记录图片在矩阵上的纵向偏移值 
    95.      */  
    96.     private float totalTranslateY;  
    97.   
    98.     /** 
    99. .relpost{clear:both}

    Tag:

    Freenovo 发表于2013-10-29 00:07:00 | 编辑 | 分享 0

    引用地址:

  • 相关阅读:
    uva 11355(极角计算)
    hdu 1029(hash)
    hdu 1024(dp)
    SPOJ DISUBSTR(字符串hash)
    SPOJ DISUBSTR(后缀数组)
    【Leetcode】Evaluate Reverse Polish Notation
    【Leetcode】Reverse Words in a String
    【Leetcode】Maximum Product Subarray
    【Leedcode】Insertion Sort List
    【Leetcode】Sort List
  • 原文地址:https://www.cnblogs.com/freenovo/p/4469796.html
Copyright © 2011-2022 走看看