4

I have an adapter for a viewPgaer where I cache images with UIL on a ImageView. I never used a ProgressBar when loading an image and it is working just fine. I dicided to make and a progress bar but when I open the activity the progress bar is spinning and after a while it is gone like it should be but the image is not displayed and in addition I can't swipe to next images. I don't know what I am doing wrong. Thank you :)

ViewPager Adapter

@Override
public Object instantiateItem(ViewGroup container, int position) {
    TouchImageView imgDisplay;

    inflater = (LayoutInflater) _activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View viewLayout = inflater.inflate(R.layout.layout_fullscreen_image, container,
            false);

    imgDisplay = (TouchImageView) viewLayout.findViewById(R.id.imgDisplay);
    final ProgressBar spinner = (ProgressBar) viewLayout.findViewById(R.id.progressBarFull);

    DisplayImageOptions options = new DisplayImageOptions.Builder()
            .cacheInMemory(true)
            .cacheOnDisk(true)
            .considerExifParams(true)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
            .build();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(_activity.getApplicationContext()).build();
    ImageLoader.getInstance().init(config);
    ImageLoader imageLoader = ImageLoader.getInstance();

    imageLoader.displayImage(_imagePaths.get(position), imgDisplay, options, new SimpleImageLoadingListener() {
        @Override
        public void onLoadingStarted(String imageUri, View view) {
            spinner.setVisibility(View.VISIBLE);
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            spinner.setVisibility(View.GONE);
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            spinner.setVisibility(View.GONE);
        }
    });

    ((ViewPager) container).addView(viewLayout);

    return viewLayout;
}

layout_fullscreen_image.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">

<com.plushost.wizgr.TouchImageView
    android:id="@+id/imgDisplay"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scaleType="fitCenter"
    android:background="#000000"/>

<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBarFull"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:visibility="gone"/>

</RelativeLayout>

Screenshot from the activity after the spinner gone enter image description here

billiout
  • 695
  • 1
  • 8
  • 22
  • Did you find solution? – Parag Chauhan Aug 10 '15 at 19:16
  • Put a log in onLoadingFailed and onLoadingComplete and check which method is being called whether image is loaded or being failed. If onLoadingComplete is called you will get the bitmap which you can directly set to the imageview. – Reyansh Mishra Jan 29 '18 at 10:58

0 Answers0