-1

I am trying to add pinch/zoom functionality to the famous bitmap project (like Gallery application). I think I have to implement this in the ImageDetailActivity.java file but I have no idea how to do ..

Is there someone who could put me on the right way ?

Or perhaps someone could have a tutorial (or sources ?) for the Gallery application (the same application we can found in all androïd phones).

Thanks !

Aravin
  • 4,126
  • 1
  • 23
  • 39
Jerry
  • 1,141
  • 1
  • 13
  • 18

2 Answers2

1

There is no reason to reinvent the wheel. Here are a few libraries that allow pinch and zoom on ImageView:

https://github.com/jasonpolites/gesture-imageview

https://github.com/chrisbanes/PhotoView

https://github.com/MikeOrtiz/TouchImageView

They are extremely simple to use, and most of them contain example code.

Elad Nava
  • 7,746
  • 2
  • 41
  • 61
  • Thanks !!! I think i will work with PhotoView. gesture-imageview and TouchImageiew are crashing with large pictures ... – Jerry Jan 25 '14 at 14:53
0

I had a example in my workspace. See if it is you want.

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.widget.TextView;
import android.widget.Toast;

public class PinchExampleActivity extends Activity {

TextView scaleText;
ScaleGestureDetector scaleGestureDetector;
private int number;
private String teste;
private int result;
private int myNum;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pinch_example);

      scaleText = (TextView)findViewById(R.id.myTextView);

      //teste = scaleText.getText().toString();

      myNum = 0;

      try {
          myNum = Integer.parseInt(scaleText.getText().toString());
      } catch(NumberFormatException nfe) {
         System.out.println("Could not parse " + nfe);
      } 
      //number = Integer.parseInt(teste);

      Toast.makeText(PinchExampleActivity.this, "fdsdfsfdsf " + myNum, Toast.LENGTH_SHORT).show();

      scaleGestureDetector = 
            new ScaleGestureDetector(this, 
                  new MyOnScaleGestureListener());
}

@Override
public boolean onTouchEvent(MotionEvent event) {
     scaleGestureDetector.onTouchEvent(event);
     return true;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.pinch_example, 
                     menu);
    return true;
}

public class MyOnScaleGestureListener extends
     SimpleOnScaleGestureListener {

     @Override
     public boolean onScale(ScaleGestureDetector detector) {

        float scaleFactor = detector.getScaleFactor();

        if (scaleFactor > 1) {
            myNum++;
            String teste = Integer.toString(myNum);

            scaleText.setText(teste);
        } else {
            myNum--;
            String teste1 = Integer.toString(myNum);
            scaleText.setText(teste1);
        }
        return true;
    }

    @Override
    public boolean onScaleBegin(ScaleGestureDetector detector) {
         return true;
    }

    @Override
    public void onScaleEnd(ScaleGestureDetector detector) {

    }
  } 
}