<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/linearLayout1"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical"    android:weightSum="1" >    <ImageView        android:id="@+id/imag"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center"        android:scaleType="matrix"        android:src="@drawable/a" >    </ImageView>    <ImageView        android:id="@+id/imag1"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:scaleType="matrix" >    </ImageView></LinearLayout>
实现代码:package hfut.gmm;import javax.swing.text.View;import javax.swing.text.html.ImageView;public class Img_control extends Activity implements OnTouchListener {//implements OnTouchListener {private ImageView imgview;private ImageView img;private Matrix matrix=new Matrix();private Matrix savedMatrix=new Matrix();static final int NONE = 0;  static final int DRAG = 1;  static final int ZOOM = 2;  int mode = NONE;  // Remember some things for zooming  PointF start = new PointF();  PointF mid = new PointF();  float oldDist = 1f;  //private GestureDetector gesture;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);this.setContentView(R.layout.img_control);imgview=(ImageView)this.findViewById(R.id.imag1);imgview.setAnimation(AnimationUtils.loadAnimation(this, R.anim.newanim));img=(ImageView)this.findViewById(R.id.imag);Matrix mt=img.getImageMatrix();//mt.postRotate(30);mt.postScale(0.5f,0.5f);mt.postScale(1.5f,1.5f);mt.postRotate(30, 130, 100);mt.postTranslate(100, 10);img.setImageMatrix(mt);//imgview.setLongClickable(true);imgview.setImageBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.a));imgview.setOnTouchListener(this);imgview.setLongClickable(true);}private float spacing(MotionEvent event) {  float x = event.getX(0) - event.getX(1);  float y = event.getY(0) - event.getY(1);  return FloatMath.sqrt(x * x + y * y);  }  private void midPoint(PointF point, MotionEvent event) {  float x = event.getX(0) + event.getX(1);  float y = event.getY(0) + event.getY(1);  point.set(x / 2, y / 2);  }  @Overridepublic boolean onTouch(View v, MotionEvent event) {// TODO Auto-generated method stub/*Log.d("Infor", "类别:"+event.getAction());Log.d("Infor", "mask:"+event.getActionMasked());Log.d("Infor", "index:"+event.getActionIndex());Log.d("Infor", "points:"+event.getPointerCount());*/Log.d("Infor", "size:"+event.getSize());if(event.getActionMasked()==MotionEvent.ACTION_POINTER_UP)Log.d("Infor", "多点操作");switch(event.getActionMasked()){case MotionEvent.ACTION_DOWN:matrix.set(imgview.getImageMatrix());savedMatrix.set(matrix);start.set(event.getX(),event.getY());Log.d("Infor", "触摸了...");mode=DRAG;break;case MotionEvent.ACTION_POINTER_DOWN:  //多点触控oldDist=this.spacing(event);if(oldDist>10f){Log.d("Infor", "oldDist"+oldDist);savedMatrix.set(matrix);midPoint(mid,event);mode=ZOOM;}break;case MotionEvent.ACTION_POINTER_UP:mode=NONE;break;case MotionEvent.ACTION_MOVE:if(mode==DRAG){         //此实现图片的拖动功能...matrix.set(savedMatrix);matrix.postTranslate(event.getX()-start.x, event.getY()-start.y);}else if(mode==ZOOM){// 此实现图片的缩放功能...float newDist=spacing(event);if(newDist>10){matrix.set(savedMatrix);float scale=newDist/oldDist;matrix.postScale(scale, scale, mid.x, mid.y);     }}break;}imgview.setImageMatrix(matrix);return false;}}

更多相关文章

  1. android 网络图片查看器
  2. Android实现振动效果
  3. Android(安卓)实现Navigation Bar和Status Bar全透明
  4. Android(安卓)volley框架加载网络图片
  5. android 处理图片工具
  6. android uninstall小工具demo实现
  7. 如何在Android中在fragment中实现点击按钮事件?
  8. Android(安卓)图片压缩
  9. 浅谈Java中Collections.sort对List排序的两种方法

随机推荐

  1. Android之Sqlite模糊查询
  2. Android(安卓)intent.Action 参数值及对
  3. Android(安卓)Animation
  4. Android(安卓)中Preferences的使用!
  5. Android通过selector改变界面状态
  6. android的进度条使用
  7. Android(安卓)studio升级AndroidX
  8. About Android; Geocoder, “the service
  9. Android(安卓)- Android(安卓)Studio 自
  10. android工程下轻松运行java main程序