How on the androyd tweak two fingers for scaling?
Is there a separate event?
- oneThere is a wonderful library for detecting gestures, including SimpleFingerGestures , including pinch / unpinch - pavlofff
|
2 answers
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:id="@+id/pinchTitleText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/pinch_title" /> <ImageView android:id="@+id/imageView" android:layout_width="300dp" android:layout_height="300dp" android:layout_below="@+id/pinchTitleText" android:scaleType="matrix" android:src="@drawable/zoom" android:maxHeight="100dp" android:maxWidth="50dp" /> </RelativeLayout> Activity
public class PinchZoomActivity extends Activity { private ImageView imageView; private ScaleGestureDetector scaleGestureDetector; private Matrix matrix = new Matrix(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView)findViewById(R.id.imageView); scaleGestureDetector = new ScaleGestureDetector(this,new ScaleListener()); } @Override public boolean onTouchEvent(MotionEvent ev) { scaleGestureDetector.onTouchEvent(ev); return true; } private class ScaleListener extends ScaleGestureDetector. SimpleOnScaleGestureListener { @Override public boolean onScale(ScaleGestureDetector detector) { float scaleFactor = detector.getScaleFactor(); scaleFactor = Math.max(0.1f, Math.min(scaleFactor, 5.0f)); matrix.setScale(scaleFactor, scaleFactor); imageView.setImageMatrix(matrix); return true; } } } For scaling images, it is better to show it in WebView , life hacking is old, but it seems to be working. Zoom must be defaulted. On a pinch here you
https://github.com/chrisbanes/PhotoView https://github.com/ongakuer/PhotoDraweeView
If you load pictures through Fresko then use the second
|
Probably the easiest way is to copy this class that extends ImageView : https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/ortiz/touch/TouchImageView.java
In the code for the xml markup file, write:
<_имя_вашего_пакета_.TouchImageView/> Good luck!
|