pinch zoom android

3

Personally my problem is the second one. I need to expand a ImageView with that well known tweezers movement, but I'm already on the third day researching the internet how to do and hitting my head, but the most I got was a tutorial code that only enlarges the image, not allowing the 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 movement of the image or if someone can help, put a code right, because as I said I hit too much head 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;
        }
    }
}
    
asked by anonymous 21.03.2015 / 20:17

2 answers

1

Try using 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"/>
    
22.03.2015 / 15:40
0

Did not try to edit the xml image which is easier? You can change the values of wrap_content to a value in pixels. Example: '' 500.0px ''

<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 zoom in within the application, the image looks like this:

SGD.setBuiltInZoomControls(true);
SGD.setSupportZoom(true);
    
21.03.2015 / 21:50