I am doing the following in my application.

1) Display a image in a activity.

2) Recognize gesture over that image.

3) And also doing pinch and zoom over the same image.

The layout I have created is given below.

*    <?xml version="1.0" encoding="utf-8"?>*
*    <FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"*
*        android:layout_width="fill_parent"*
*        android:layout_height="fill_parent" >*

*    <ImageView*
*        android:id="@+id/showImg"*
*        android:layout_width="wrap_content"*
*        android:layout_height="wrap_content"*
*        android:layout_gravity="center"*
*        android:scaleType="matrix"*
*        android:src="@drawable/image" >*
*    </ImageView>*

*    </FrameLayout>*

And I am using the following code for the "pinch zoom" and "gesture 
overlayview" (detect the gesture).

*    public class Touch extends Activity implements OnTouchListener {*
*    private static final String TAG = "Touch";*

* // These matrices will be used to move and zoom image*
* Matrix matrix = new Matrix();*
* Matrix savedMatrix = new Matrix();*

* // We can be in one of these 3 states*
* 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;*

* @Override*
* public void onCreate(Bundle savedInstanceState) {*
* super.onCreate(savedInstanceState);*
* GestureOverlayView gestureOverlayView = new GestureOverlayView(this);*
* View inflate = getLayoutInflater().inflate(R.layout.main, null);*
* gestureOverlayView.addView(inflate);*

* ImageView img = (ImageView) inflate.findViewById(R.id.showImg);*
* img.setScaleType(ImageView.ScaleType.FIT_CENTER);*
* img.setOnTouchListener(this);*

* setContentView(gestureOverlayView);*
* }*

* public boolean onTouch(View v, MotionEvent event) {*
* ImageView view = (ImageView) v;*
* view.setScaleType(ImageView.ScaleType.MATRIX);*
* float scale;*

* // Dump touch event to log*
* dumpEvent(event);*

* // Handle touch events here...*
* switch (event.getAction() & MotionEvent.ACTION_MASK) {*

* case MotionEvent.ACTION_DOWN: // first finger down only *
* Log.d(TAG, "mode=DRAG");*
* mode = DRAG;*
* break;*
* case MotionEvent.ACTION_UP: // first finger lifted*
* case MotionEvent.ACTION_POINTER_UP: // second finger lifted*
* mode = NONE;*
* Log.d(TAG, "mode=NONE");*
* break;*
* case MotionEvent.ACTION_POINTER_DOWN: // second finger down*
* oldDist = spacing(event);*
* Log.d(TAG, "oldDist=" + oldDist);*
* if (oldDist > 5f) {*
* savedMatrix.set(matrix);*
* midPoint(mid, event);*
* mode = ZOOM;*
* Log.d(TAG, "mode=ZOOM");*
* }*
* break;*

* case MotionEvent.ACTION_MOVE:*
* if (mode == DRAG) { // movement of first finger*
* } else if (mode == ZOOM) { // pinch zooming*
* float newDist = spacing(event);*
* Log.d(TAG, "newDist=" + newDist);*
* if (newDist > 5f) {*
* matrix.set(savedMatrix);*
* scale = newDist / oldDist; // thinking i need to play around*
* // with this value to limit it*
* matrix.postScale(scale, scale, mid.x, mid.y);*
* }*
* }*
* break;*
* }*

* // Perform the transformation*
* view.setImageMatrix(matrix);*

* return true; // indicate event was handled*
* }*

* 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);*
* }*

* /** Show an event in the LogCat view, for debugging */*
* private void dumpEvent(MotionEvent event) {*
* String names[] = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE",*
* "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" };*
* StringBuilder sb = new StringBuilder();*
* int action = event.getAction();*
* int actionCode = action & MotionEvent.ACTION_MASK;*
* sb.append("event ACTION_").append(names[actionCode]);*
* if (actionCode == MotionEvent.ACTION_POINTER_DOWN*
* || actionCode == MotionEvent.ACTION_POINTER_UP) {*
* sb.append("(pid ").append(*
* action >> MotionEvent.ACTION_POINTER_ID_SHIFT);*
* sb.append(")");*
* }*
* sb.append("[");*
* for (int i = 0; i < event.getPointerCount(); i++) {*
* sb.append("#").append(i);*
* sb.append("(pid ").append(event.getPointerId(i));*
* sb.append(")=").append((int) event.getX(i));*
* sb.append(",").append((int) event.getY(i));*
* if (i + 1 < event.getPointerCount())*
* sb.append(";");*
* }*
* sb.append("]");*
* Log.d(TAG, sb.toString());*
* }*
*}*

The issue is mentioned below.

The zoom is not working perfectly. sometimes, I do a pinch or zoom, it is 
not working. 

**NOTE: But when I remove the "GestureOverlayView", the pinch and zoom 
working perfectly over that imageview. But I need "GestureOverlayView" to 
detect gesture.**

Is this a android issue or the coding issue? How can I fix this?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to