protected void init() { if (null == mAttacher || null == mAttacher.getImageView()) { mAttacher = new PhotoViewAttacher(this); } if (null != mPendingScaleType) { setScaleType(mPendingScaleType); mPendingScaleType = null; } }
@Override public Object instantiateItem(ViewGroup container, int position) { PhotoView photo = new PhotoView(container.getContext()); photo.setScaleType(ImageView.ScaleType.FIT_CENTER); // Load Image from URL using Glide Glide.with(activity) .load(imagesList.get(position)) .crossFade() .diskCacheStrategy(DiskCacheStrategy.ALL) .into(photo); container.addView( photo, ViewPager.LayoutParams.MATCH_PARENT, ViewPager.LayoutParams.MATCH_PARENT); return photo; }
/** 用来实例化页卡 */ @Override public Object instantiateItem(ViewGroup container, int position) { PhotoView photoView = new PhotoView(mContext); // photoView.setScaleType(ImageView.ScaleType.CENTER); photoView.setScaleType(ImageView.ScaleType.FIT_CENTER); Glide.with(mContext).load(mPictures.get(position)).into(photoView); // Now just add PhotoView to ViewPager and return it container.addView( photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); // 单击图片 photoView.setOnPhotoTapListener( new PhotoViewAttacher.OnPhotoTapListener() { @Override public void onPhotoTap(View view, float v, float v1) { mOnSingleClickListener.singleClickFinish(); } @Override public void onOutsidePhotoTap() { mOnSingleClickListener.singleClickFinish(); } }); return photoView; }