Viewpager + Image PinchZoom+ Async Image Loader

Step 1: Used Customize ViewPager
public class ExtendedViewPager extends ViewPager {

public ExtendedViewPager(Context context) {
super(context);
}

public ExtendedViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (v instanceof ImageViewTouch) {
ImageViewTouch imageViewTouch = (ImageViewTouch) v;
if (imageViewTouch.getScale() == imageViewTouch.getMinScale()) {
return super.canScroll(v, checkV, dx, x, y);
}
return imageViewTouchCanScroll(imageViewTouch, dx);
} else {
return super.canScroll(v, checkV, dx, x, y);
}
}

private boolean imageViewTouchCanScroll(ImageViewTouch v, int direction) {
RectF bitmapRect = v.getBitmapRect();
Rect imageViewRect = new Rect();
getGlobalVisibleRect(imageViewRect);

if (null == bitmapRect) {
return false;
}

if (direction < 0) {
return Math.abs(bitmapRect.right - imageViewRect.right) > 1.0f;
} else {
return Math.abs(bitmapRect.left - imageViewRect.left) > 1.0f;
}

}

}

Step 2: For ImageZoom and Scalable :

Used This Library : https://github.com/sephiroth74/ImageViewZoom/tree/master/library/src/main/java/it/sephiroth/android/library/imagezoom

Directly add this library folder in java packages.

Step 3 : Make Fragment For Viewpager Adapter :
public class ViewPagerFragment extends Fragment {

MasterPageModel masteDetailModel;

public ViewPagerFragment(MasterPageModel questionItem) {
this.masteDetailModel = questionItem;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.pagerlayout, container, false);

final ImageViewTouch image = (ImageViewTouch) v.findViewById(R.id.pager_imageview);
DetailSwipeActivity activity = (DetailSwipeActivity) getActivity();
Glide.with(activity).load(masteDetailModel.imagepath).asBitmap().error(R.drawable.img).into(new SimpleTarget() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
image.setImageBitmap(resource);
}
});

return v;
}

}

step 4 : Make your Viewpager Adapter
public class PagerAdapter extends FragmentStatePagerAdapter {

private final List<MasterPageModel> pages;

public PagerAdapter(FragmentManager fm, List<MasterPageModel> pages) {
super(fm);
this.pages = pages;
}


@Override
public Fragment getItem(int position) {
return new ViewPagerFragment(pages.get(position));
}

@Override
public CharSequence getPageTitle(int position) {
int pageitem = position;
pageitem = pageitem + 1;
return "Page " + pageitem;
}

@Override
public int getCount() {
return pages.size();
}
}

 

Contributer

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments:

Hot-product

Best Watch Store

Popular Posts

Contact Form

Name

Email *

Message *