ImageView no longer exists. You should not use this PhotoViewAttacher any more
- Dominant language
- Java
- Stars
- 18.8k
- Forks
- 3.9k
- PR merge metrics
- No merged PRs in 30d
Description
@chrisbanes
@Jawnnypoo
the build.gradle is :
dependencies {
compile 'com.commit451:PhotoView:1.2.4'
}
This my code :
class PhotoPreviewAdapter extends PagerAdapter {
@Override
public int getCount() {
return photoModelList != null ? photoModelList.size() : 0;
}
```
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
FrameLayout frameLayout = new FrameLayout(container.getContext());
frameLayout.setBackgroundColor(Color.BLACK);
PhotoView photoView = new PhotoView(container.getContext());
photoView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
String imageUrl = "file://" + photoModelList.get(position).getOriginalPath();
GlideLoader.loadImg(PhotoPreviewActivity.this, photoView, imageUrl);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER;
frameLayout.addView(photoView, params);
container.addView(frameLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
return frameLayout;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
}
```
and load Image:
public static void loadImg(Context context, ImageView imageView, String url) {
Glide.with(context).load(url).placeholder(R.drawable.bg_loading)
.error(R.drawable.bg_load_failed)
.crossFade()
.centerCrop()
.dontAnimate()
.into(imageView);
}
when i scoll left and right , it happened the warn : ImageView no longer exists. You should not use this PhotoViewAttacher any more
I don't know the reason , can you tell me how to solve the problem.
I found if use viewpager.setCurrentItem(position), but adapter still load position 0 to 1 ,then destroyItem and load image will use the imageview is null , how to avoid this situation.
Contributor guide
Assessment
This issue has not been assessed yet.