Pinch android zoom

Asked

Viewed 376 times

3

Personal my problem is the second. I need to enlarge a ImageView with that movement of forceps well known, but I’m already in the third day researching on the internet how to do and banging the head, But the most I could get was a tutorial code that just magnifies the image by not allowing the movement of the enlarged image it only magnifies at a fixed point and stays. I will be putting the code and I would like to know how to implement the image movement or if anyone can help, put a code right, because as I said I hit my head too much and nothing came out here rsrs. Hugs.

public class tela87 extends SherlockFragmentActivity {

    private ImageView img;
    private Matrix matrix = new Matrix();
    private float scale = 1f;
    private ScaleGestureDetector SGD;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tela835gavetti);
        img = (ImageView)findViewById(R.id.imageView1);
        SGD = new ScaleGestureDetector(this,new ScaleListener());
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        SGD.onTouchEvent(ev);
        return true;
    }

    private class ScaleListener extends ScaleGestureDetector.
            SimpleOnScaleGestureListener {
        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            scale *= detector.getScaleFactor();
            scale = Math.max(0.1f, Math.min(scale, 5.0f));
            matrix.setScale(scale, scale);
            img.setImageMatrix(matrix);
            return true;
        }
    }
}

2 answers

1

Try to use the TouchImageView, it supports Pinch zoom, double tap and other features.

To implement it, just reference it in your layout:

<br.com.seupacote.TouchImageView
    android:id="@+id/touch_img_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:scaleType="centerCrop"/>

0

Didn’t you try to edit the xml image which is easier? You can change the wrap_content values to a pixel value. Example: ''500.0 px''

<ImageView 
  android:id="@+id/img"     
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content"  
  android:adjustViewBounds="true"  
  android:maxWidth="42dp"  
  android:maxHeight="42dp"  
  android:scaleType="fitCenter"  
  android:layout_marginLeft="3dp"  
  android:src="@drawable/minhaimagem"  
  /> 

To enlarge inside the application the image try so:

SGD.setBuiltInZoomControls(true);
SGD.setSupportZoom(true);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.