English | 简体中文
A gesture-friendly and easy-to-use image pinch-zoom control. It extends ImageView
, is contained in a single class file, has no external dependencies, and is lightweight and easy to integrate.
1) Copy PinchImageView.java
into your project.
2) Add the following code to your layout file; it can already display an image from resources:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.boycy815.pinchimageview.PinchImageView
android:id="@+id/pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="https://github.com/boycy815/PinchImageView/raw/master/@drawable/my_pic"/>
</RelativeLayout>
3) Use it directly as an ImageView
:
// Retrieve it as an ImageView
ImageView imageView = (ImageView) findViewById(R.id.pic);
// You can set the image using any method supported by ImageView
imageView.setImageResource(R.drawable.my_pic);
// or...
imageView.setImageBitmap(bitmap);
// or...
imageView.setImageDrawable(drawable);
// or you can even use third-party image loading libraries, like ImageLoader
imageLoader.displayImage("http://host.com/my_pic.jpg", imageView);