android矩阵实现图片随意放大缩小或拖动

  

本文实例为大家分享了android矩阵图片随意放大缩小和拖动的具体代码,供大家参考,具体内容如下

  

<强>步骤1:新建一个项目DragAndZoom,并准备一张照片放在res/drawable-hdpi目录下,如下图所示:

  

 android矩阵实现图片随意放大缩小或拖动

  

<强>步骤2:设置应用的UI界面,在主要。xml中设置:
  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android:取向=按怪薄?   android: layout_width="宽和"   android: layout_height="宽和"   比;   & lt; ImageView   android: layout_width="宽和"   android: layout_height=" wrap_content "   android: src=" https://www.yisu.com/zixun/@drawable墙”   android: id=癅 + id/imageView”   android: scaleType=熬卣蟆?比;& lt; !——指定类为矩阵型——比;   & lt;/LinearLayout>   之前      

<强>步骤3: MainActivity。java中实现具体的需求
  

        包cn.roco.drag;      进口android.app.Activity;   进口android.graphics.Matrix;   进口android.graphics.PointF;   进口android.os.Bundle;   进口android.util.FloatMath;   进口android.view.MotionEvent;   进口android.view.View;   进口android.view.View.OnTouchListener;   进口android.widget.ImageView;      公开课MainActivity延伸活动{      私人ImageView ImageView;      @Override   公共空间>   & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;清单xmlns: android=" http://schemas.android.com/apk/res/android "   包=" cn.roco.drag "   android: versionCode=" 1 "   android: versionName=" 1.0 "比;   & lt; uses-sdk android: minSdkVersion=" 8 "/比;=& lt;应用android:图标“@drawable/图标”android:标签=癅string/app_name”比;   & lt;活动android: name=" .MainActivity "   android: label=" @string/app_name”比;   & lt; intent-filter>   & lt;行动android: name=" android.intent.action.MAIN "/比;   & lt;类别android: name=" android.intent.category.LAUNCHER "/比;   & lt;/intent-filter>   & lt;/activity>      & lt;/application>   & lt;/manifest>之前      

<强>顾不上具体的效果图
  

  

 android矩阵实现图片随意放大缩小或拖动

  

 android矩阵实现图片随意放大缩小或拖动“> <br/>
  </p>
  <p>上面两个是图片拖拽的效果,而图片的缩放效果要在真机中才能够看得到,请读者自己在真机环境中测试。</p>
  <p>具体的程序源码在:下载程序源码</p>
  <p>其实通过通过手势也可以缩放图片,左——→右放大右——→左缩小速度越快,缩放比例越大<br/>
  </p>
  <p>变焦。xml <br/>
  </p>
  
  <pre类=   & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android:取向=按怪薄?   android: layout_width="宽和"   android: layout_height="宽和"   比;   & lt; ImageView   android: layout_width="宽和"   android: layout_height=" wrap_content "   android: src=" https://www.yisu.com/zixun/@drawable墙”   android: id=癅 + id/显示”   android: scaleType=熬卣蟆?比;& lt; !——指定类为矩阵型——比;   & lt;/LinearLayout>   之前      

GestureZoom。java
  

        包cn.roco.gesture;      进口android.app.Activity;   进口android.graphics.Bitmap;   进口android.graphics.BitmapFactory;   进口android.graphics.Matrix;   进口android.graphics.drawable.BitmapDrawable;   进口android.os.Bundle;   进口android.view.GestureDetector;   进口android.view.GestureDetector.OnGestureListener;   进口android.view.MotionEvent;   进口android.widget.ImageView;/* *   *通过手势缩放图片左——→右放大右——→左缩小速度越快,缩放比例越大   */公共类GestureZoom扩展活动实现alt=" android矩阵实现图片随意放大缩小或拖动”>,,,,

  

 android矩阵实现图片随意放大缩小或拖动

android矩阵实现图片随意放大缩小或拖动