This library has copied from Jason Polites's gesture-imageview repository, fixed couple of bugs and merged with pull requests from other users.
This is a simple Android View class which provides basic pinch and zoom capability for images.
Can be used as a replacement for a standard ImageView when you want to include pinch and zoom.
Add dependency in your build.gradle
implementation 'com.cuneytayyildiz:gestureimageview:1.0.0'
- Pinch zoom in place (i.e. zoom occurs from point of touch)
- Panning with fling gesture
- Double tap zoom
- Configurable zoom boundaries (min/max)
- Does not support Rotation
- Does not support Pan and Zoom together
- Not all methods of ImageView class are supported (will throw UnsupportedOperationException if strict is true)
- Setting gesture-image:strict to true will result in UnsupportedOperationException if an unsupported method is called. Default value: false
- Setting gesture-image:recycle to true will automatically reycle bitmap images when the view is destroyed. Default value: false
Configured as View in layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.polites.com/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.cuneytayyildiz.gestureimageview.GestureImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/image"
app:gi_min_scale="0.1"
app:gi_max_scale="10.0"
app:gi_strict="false"/>
</LinearLayout>
Configured Programmatically
import com.cuneytayyildiz.gestureimageview.GestureImageView;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout.LayoutParams;
public class SampleActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
GestureImageView view = new GestureImageView(this);
view.setImageResource(R.drawable.image);
view.setLayoutParams(params);
ViewGroup layout = (ViewGroup) findViewById(R.id.layout);
layout.addView(view);
}
}