Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I hope that maybe useful simple solution. Don't forget voteup. Used custom ImageView</p> <pre><code>private void sharedConstructing(final Context context) { super.setClickable(true); this.context = context; mScaleDetector = new ScaleGestureDetector(context, new ScaleListener()); matrix.setTranslate(1f, 1f); m = new float[9]; setImageMatrix(matrix); setScaleType(ScaleType.MATRIX); setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { mScaleDetector.onTouchEvent(event); matrix.getValues(m); float x = m[Matrix.MTRANS_X]; float y = m[Matrix.MTRANS_Y]; PointF curr = new PointF(event.getX(), event.getY()); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: last.set(event.getX(), event.getY()); start.set(last); if (minScale &lt; saveScale){ mode = DRAG; Toast msg = Toast.makeText(context, "Drag mode", Toast.LENGTH_SHORT); msg.show(); // msg1.show(); } break; case MotionEvent.ACTION_MOVE: if (mode == DRAG) { float deltaX = curr.x - last.x; float deltaY = curr.y - last.y; float scaleWidth = Math.round(origWidth * saveScale); float scaleHeight = Math.round(origHeight * saveScale); if (scaleWidth &lt; width) { deltaX = 0; if (y + deltaY &gt; 0) deltaY = -y; else if (y + deltaY &lt; -bottom) deltaY = -(y + bottom); } else if (scaleHeight &lt; height) { deltaY = 0; if (x + deltaX &gt; 0) deltaX = -x; else if (x + deltaX &lt; -right) deltaX = -(x + right); } else { if (x + deltaX &gt; 0) deltaX = -x; else if (x + deltaX &lt; -right) deltaX = -(x + right); if (y + deltaY &gt; 0) deltaY = -y; else if (y + deltaY &lt; -bottom) deltaY = -(y + bottom); } matrix.postTranslate(deltaX, deltaY); last.set(curr.x, curr.y); } break; case MotionEvent.ACTION_UP: mode = NONE; int xDiff = (int) Math.abs(curr.x - start.x); int yDiff = (int) Math.abs(curr.y - start.y); if (saveScale==minScale &amp;&amp; (start.x-curr.x) &gt; SWIPE_MIN_DISTANCE ) { GestureDetector gestureDetector = new GestureDetector(new GestureListener()); mode = FLING; Toast msg2 = Toast.makeText(context, "Fling mode left to right", Toast.LENGTH_SHORT); msg2.show(); } else if (saveScale==minScale &amp;&amp; (curr.x-start.x) &gt; SWIPE_MIN_DISTANCE){ mode = FLING; GestureDetector gestureDetector = new GestureDetector(new GestureListener()); Toast msg2 = Toast.makeText(context, "Fling mode right to left", Toast.LENGTH_SHORT); msg2.show(); } if (xDiff &lt; CLICK &amp;&amp; yDiff &lt; CLICK) performClick(); break; case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; } setImageMatrix(matrix); invalidate(); return true; // indicate event was handled } }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload