Zoom in and out images (Use smooth display with ViewPager)-third-party Open Source-PhotoView,
Image zoom-in and zoom-out effect is achieved using an open source project photoView on github,: https://github.com/chrisbanes/PhotoView
The test code is as follows:
Activity_main.xml:
1 <RelativeLayout xmlns: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.ViewPager 7 android:id="@+id/viewPager" 8 android:layout_width="match_parent" 9 android:layout_height="match_parent" >10 </android.support.v4.view.ViewPager>11 12 </RelativeLayout>
MainActivity. java:
1 package com. zzw. tetsphotoview; 2 3 import java. util. arrayList; 4 import java. util. list; 5 6 import uk. co. senab. photoview. photoViewAttacher; 7 8 import android. app. activity; 9 import android. content. context; 10 import android. OS. bundle; 11 import android. OS. handler; 12 import android. OS. message; 13 import android. support. v4.view. pagerAdapter; 14 import android. support. v4.view. viewPager; 15 import android. view. view; 16 import android. view. viewGroup; 17 import android. widget. imageView; 18 19 public class MainActivity extends Activity {20 ViewPager mViewPager; 21 List <ImageView> imageViews; 22 23 @ Override24 protected void onCreate (Bundle savedInstanceState) {25 super. onCreate (savedInstanceState); 26 setContentView (R. layout. activity_main); 27 mViewPager = (ViewPager) findViewById (R. id. viewPager); 28 mViewPager. setAdapter (new ImageAdapter (this); 29} 30 31 class ImageAdapter extends PagerAdapter {32 Context context; 33 int [] images; 34 35 public void init () {36 imageViews = new ArrayList <ImageView> (); 37 images = new int [] {R. drawable. a, R. drawable. b, R. drawable. c, R. drawable. d}; 38 for (int I = 0; I <images. length; I ++) {39 ImageView image = new ImageView (context); 40 image. setImageResource (images [I]); 41 42 // enables the image to be zoomed in and out 43PhotoViewAttacher mAttacher = new PhotoViewAttacher (image );44 45 46 imageViews. add (image); 47 48 49} 50 // for (int I: images) {51 // ImageView image = new ImageView (context); 52 // image. setImageResource (I); 53 // imageViews. add (image); 54 //} 55} 56 57 public ImageAdapter (Context context) {58 this. context = context; 59 init (); 60} 61 62 @ Override63 public void destroyItem (ViewGroup container, int position, Object object) {64 container. removeView (imageViews. get (position); 65} 66 67 @ Override68 public View instantiateItem (ViewGroup container, int position) {69 container. addView (imageViews. get (position); 70 71 return imageViews. get (position); 72} 73 74 @ Override75 public int getCount () {76 return imageViews. size (); 77} 78 79 @ Override80 public boolean isViewFromObject (View arg0, Object arg1) {81 return arg0 = arg1; 82} 83 84} 85 86}