package com.c;
import android.app.Activity;
import android.graphics.Matrix;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;
public class New extends Activity {
 final static float STEP = 200;
 float mRatio = 1.0f;
 int mBaseDist;
 float mBaseRatio;
 ImageView mImg;
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.c23_imagezoom);
  mImg = (ImageView)findViewById(R.id.img);
 }
 public boolean onTouchEvent(MotionEvent event) {
  if (event.getPointerCount() == 2) {
   int action = event.getAction();
   int pureaction = action & MotionEvent.ACTION_MASK;
   if (pureaction == MotionEvent.ACTION_POINTER_DOWN) {
    mBaseDist = getDistance(event);
    mBaseRatio = mRatio;
   } else {
    float delta = (getDistance(event) - mBaseDist) / STEP;
    float multi = (float)Math.pow(2, delta);
    mRatio = Math.min(1024.0f, Math.max(0.1f, mBaseRatio * multi));
    Matrix m = new Matrix();
    m.postScale(mRatio, mRatio);
    mImg.setImageMatrix(m);
   }
  }
  return true; 
 }
 int getDistance(MotionEvent event) {
  int dx = (int)(event.getX(0) - event.getX(1));
  int dy = (int)(event.getY(0) - event.getY(1));
  return (int)(Math.sqrt(dx * dx + dy * dy));
 }
}

 

 

 package com.c;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class Pinch extends Activity {
 
 NaviImageView nImageView;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
//    WindowManager.LayoutParams.FLAG_FULLSCREEN);
       
//        requestWindowFeature(Window.FEATURE_NO_TITLE);
         nImageView = new NaviImageView(this);
        nImageView.setBitmap( BitmapFactory.decodeResource(getResources(), R.drawable.school_bus));
         setContentView(nImageView);
    }
     class NaviImageView extends View {
 /** 이미지 **/
     public Bitmap image = null;
     
     private float startX = 0;
     private float startY = 0;
     
     private float userX = 0;
     private float userY = 0;
     
     final static int TOUCH_TOLERANCE = 4;
     
     public NaviImageView(Context context) {
      super(context);
      // TODO Auto-generated constructor stub
     }
     public NaviImageView(Context context, AttributeSet attrs) {
      super(context, attrs);
      // TODO Auto-generated constructor stub
     }
     public NaviImageView(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
      // TODO Auto-generated constructor stub
     }
     public void setBitmap(Bitmap temp) {

      image = temp;
      userX = -1400;
      userY = -50;
//      userX = (image.getWidth() - getWindowManager().getDefaultDisplay().getWidth())/ -2;
//      userY = (image.getHeight() - getWindowManager().getDefaultDisplay().getHeight())/ -2;
     }

     @Override
     protected void onDraw(Canvas canvas) {
      // TODO Auto-generated method stub

   if ( image != null)
    canvas.drawBitmap(image,  userX,  userY, null);
     }
     
     @Override
     public boolean onTouchEvent(MotionEvent event) {
      // TODO Auto-generated method stub
      
      float x = event.getX();
      float y = event.getY();
      
      switch ( event.getAction() ) {
      
      case MotionEvent.ACTION_DOWN:

       setUserNavi(x, y);

       break;
       
      case MotionEvent.ACTION_MOVE:

       processNavi(x, y);
    setUserNavi(x, y);
    
       invalidate();
       
       break;
       
      case MotionEvent.ACTION_UP:
       
       clearStartPoint();
       invalidate();
       
       break;
      }
      
      return true;
     }
     
     
     
     private void processNavi(float x, float y) {
      
      if( Math.abs( (startX - x)) > TOUCH_TOLERANCE ||
        Math.abs( (startY - y) ) > TOUCH_TOLERANCE ) {
       
    if ( startX > x )
     userX -= (startX - x );
    else
     userX += ( x - startX );
    
    if ( startY < y)
     userY += ( y - startY );
    else
     userY -= (startY - y);
   }
     }
     
     
     
     
     
     private void setUserNavi(float x, float y) {
      startX = x; startY = y;
     }
     
     private void clearStartPoint() {
      startX = startY = 0;
     }
    }
}


 

 

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 >
<ImageView
 android:id="@+id/img" 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:src="@drawable/school_bus"
 android:scaleType="matrix"
 />
</LinearLayout>


 

첫번째소스는 이미지 확대축소하는 클래스이고

두번째소스는 이미지를 상하좌우대각선으로 움직이는 클래스 입니다.

그리고 마지막은 xml파일 입니다. 위에 두 클래스를 합쳐주세요..ㅠㅠ