In this project, i have merged Picaso & PhotoView libraries to make a simple app to show remote images with sliding, double-tap & Pinch to Zoom effects using ViewPager & PhotoView respectively.
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
and add this code itno your project build.gradle file
allprojects {
repositories {
maven { url "https://www.jitpack.io" }
}
}
buildscript {
repositories {
maven { url "https://www.jitpack.io" }
}
}
you can find latest versions of picaso at this & this
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
public class ViewPagerAdapter extends PagerAdapter {
private final Context context;
private final String[] imageUrls;
ViewPagerAdapter(Context context, String[] imageUrls) {
this.context = context;
this.imageUrls = imageUrls;
}
@Override
public int getCount() {
return imageUrls.length;
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
PhotoView imageView = new PhotoView(context);
Picasso.get()
.load(imageUrls[position])
.into(imageView);
container.addView(imageView);
return imageView;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
}
String[] imageUrls = new String[]{
"https://cdn.pixabay.com/photo/2016/11/11/23/34/cat-1817970_960_720.jpg",
"https://cdn.pixabay.com/photo/2017/12/21/12/26/glowworm-3031704_960_720.jpg",
"https://cdn.pixabay.com/photo/2017/12/24/09/09/road-3036620_960_720.jpg",
"https://cdn.pixabay.com/photo/2017/11/07/00/07/fantasy-2925250_960_720.jpg",
"https://cdn.pixabay.com/photo/2017/10/10/15/28/butterfly-2837589_960_720.jpg"
};
ViewPager viewPager = findViewById(R.id.viewpager);
ViewPagerAdapter adapter = new ViewPagerAdapter(this, imageUrls);
viewPager.setAdapter(adapter);
<uses-permission android:name="android.permission.INTERNET" />
And that's it :)