There are many pictures on the internet on the scale of the demo, I do not feel very good, recently on GitHub saw a simple support multi-finger zoom image of the Android view class Gesture-imageview (address: https:// Github.com/jasonpolites/gesture-imageview), feel pretty good, now write a demo convenient later used to call
The first step: Add the library, the recommended direct download zip, import project, directly to the main com.polites.android package directly copied to their project, to facilitate their own later modification
The second step: because I only need to use the Gestureimageview class, so this example only calls the class
Here's the code: Mainactivity.java
PackageCom.example.android_imageview;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportCom.polites.android.GestureImageView; Public classMainactivityextendsActivityImplementsonclicklistener{protectedGestureimageview View; Button Btn_save,btn_close; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); View=(Gestureimageview) Findviewbyid (r.id.gestureimage_image); //This example only uses the local image as an example image, the picture can be changed arbitrarilyView.setimageresource (R.drawable.ic_launcher); } @Override Public voidOnClick (View arg0) {if(Arg0.getid () = =R.id.btn_save) { //method for saving pictures }Else if(Arg0.getid () = =r.id.btn_close) { //Close Activityfinish (); } }}
Layout file: Activity_main.xml
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"xmlns:gesture-image= "Http://schemas.polites.com/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "#000000" > <Com.polites.android.GestureImageView Android:id= "@+id/gestureimage_image"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:layout_centerinparent= "true"gesture-image:min-scale= "0.75"gesture-image:max-scale= "10.0"/> <Button Android:id= "@+id/btn_save"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true"Android:text= "Save"/> <Button Android:id= "@+id/btn_close"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentright= "true"Android:layout_alignparenttop= "true"Android:text= "Close"/></relativelayout>
Note: Relativelayout in the xmlns:gesture-image=http://schemas.polites.com/android must be added, otherwise the words will be error, the following three properties to control the image zoom
Gesture-image:min-scale Scaling Minimum Gesture-image:max-scale scaling maximum gesture-image:strict is accurate
Additional sentence: Gestureimageview usage and ImageView use the same way.
You can also look at the source code, a little clearer