I. Overview
Android pictures to achieve: swipe gesture, double-click the larger, multi-touch effect. In fact, there is a certain difficulty, we need to use matrix, gesturedetector and so on need to complete a complex logic to achieve, but today I want to say is not this method, but a third-party library Photoview, It takes only 3-5 lines of code to finish zooming the picture. Isn't that cool?
Two. How to use
Github:https://github.com/chrisbanes/photoview
If using as required in the introduction of the following library files (currently the latest):
dependencies { ' com.commit451:photoview:1.2.4'}
The configuration is so simple
Three. Code Demo
Public classMainactivityextendsappcompatactivity {PrivatePhotoView PhotoView; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Initialize (); ShowData (); } Private voidShowData () {//Loading PicturesGlide.with ( This). Load (r.mipmap.temp). Asbitmap (). into (PhotoView); } Private voidInitialize () {PhotoView=(PhotoView) Findviewbyid (R.id.photoview); }}
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <Uk.co.senab.photoview.PhotoViewAndroid:id= "@+id/photoview"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" /></LinearLayout>
Run the effect as follows, support drag up and down, directly double-click to large, double-click the full screen again, double-click Restore and other effects, support multi-touch zoom, any sliding
The above code uses the glide display picture, so the project needs to introduce the glide library:
Compile ' com.github.bumptech.glide:glide:3.6.1 '
For more information about glide, refer to:
Zoom effect on Android images