Zoom in and out (use smooth display with Viewpager)--third party open source--photoview

Source: Internet
Author: User

The zoomed-out effect of the image is achieved using an open source project on GitHub, PhotoView: Https://github.com/chrisbanes/PhotoView

Here's a look at the test code:

Activity_main.xml:

1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent" >5 6     <Android.support.v4.view.ViewPager7         Android:id= "@+id/viewpager"8 Android:layout_width= "Match_parent"9 Android:layout_height= "Match_parent" >Ten     </Android.support.v4.view.ViewPager> One  A </Relativelayout>

Mainactivity.java:

1  PackageCom.zzw.tetsphotoview;2 3 Importjava.util.ArrayList;4 Importjava.util.List;5 6 ImportUk.co.senab.photoview.PhotoViewAttacher;7 8 Importandroid.app.Activity;9 ImportAndroid.content.Context;Ten ImportAndroid.os.Bundle; One ImportAndroid.os.Handler; A ImportAndroid.os.Message; - ImportAndroid.support.v4.view.PagerAdapter; - ImportAndroid.support.v4.view.ViewPager; the ImportAndroid.view.View; - ImportAndroid.view.ViewGroup; - ImportAndroid.widget.ImageView; -  +  Public classMainactivityextendsActivity { - Viewpager Mviewpager; +List<imageview>imageviews; A  at @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -Mviewpager =(Viewpager) Findviewbyid (R.id.viewpager); -Mviewpager.setadapter (NewImageadapter ( This)); in     } -  to     classImageadapterextendsPageradapter { + context context; -         int[] images; the  *          Public voidinit () { $Imageviews =NewArraylist<imageview>();Panax NotoginsengImages =New int[] {r.drawable.a, r.drawable.b, r.drawable.c, R.DRAWABLE.D}; -              for(inti = 0; i < images.length; i++) { theImageView image =NewImageView (context); + Image.setimageresource (Images[i]); A                  the                 //The ability to zoom in and out of a picture +                 photoviewattacher mattacher=new photoviewattacher (image); -                  $                  $ Imageviews.add (image); -             -              the             } - //for (int i:images) {Wuyi //ImageView image = new ImageView (context); the //Image.setimageresource (i); - //Imageviews.add (image); Wu //             } -         } About  $          PublicImageadapter (Context context) { -              This. Context =context; - init (); -         } A  + @Override the          Public voidDestroyitem (ViewGroup container,intposition, Object object) { - Container.removeview (imageviews.get (position)); $         } the  the @Override the          PublicView Instantiateitem (ViewGroup container,intposition) { the Container.addview (imageviews.get (position)); -  in             returnImageviews.get (position); the         } the  About @Override the          Public intGetCount () { the             returnimageviews.size (); the         } +  - @Override the          Public BooleanIsviewfromobject (View arg0, Object arg1) {Bayi             returnarg0 = =arg1; the         } the  -     } -  the}

Zoom in and out (use smooth display with Viewpager)--third party open source--photoview

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.