Zoom effect on Android images

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.