Search code examples
androidaquery

Android aquery image loading both with placeholder and progressbar


I am trying to use aquery for image loading. Here is my layout:

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

    <ProgressBar                
        android:layout_width="60dip"       
        android:layout_height="60dip"
        android:id="@+id/progress" 
        android:layout_centerInParent="true"
        />

     <ImageView
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:id="@+id/imageViewPagerImage"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:scaleType="fitCenter" />
</RelativeLayout>

I use aquery like the following:

Bitmap placeholder;
@Override
public Object instantiateItem(ViewGroup container, int position) {
    View itemView = mLayoutInflater.inflate(R.layout.product_detail_pager_item, container, false);

    ImageView imageView = (ImageView) itemView.findViewById(R.id.imageViewPagerImage);
    placeholder = null;
    placeholder = androidQuery.getCachedImage(R.drawable.product_detail_big);
    androidQuery.id(imageView).progress(R.id.progress).image(allUrls.get(position), false, true, 0, 0, placeholder, Constants.FADE_IN);
    imageView.setOnClickListener(listener);
    container.addView(itemView);

    return itemView;
}

The problem is, placeholder image is shown until image is loaded but progressbar is not shown. If i put progressbar below the imageview in my xml layout like the following:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
     <ImageView
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:id="@+id/imageViewPagerImage"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:scaleType="fitCenter" />

     <ProgressBar                
        android:layout_width="60dip"       
        android:layout_height="60dip"
        android:id="@+id/progress" 
        android:layout_centerInParent="true" />
</RelativeLayout>

This time both placeholder and progressbar is displayed, but progressbar does not disappear after image is loaded. I want to show both placeholder and progressbar, but i want progressbar to disappear after image is loaded. Can anyone help me with this?

Thanks.


Solution

  • I found the problem.

    It seems that i have to get the reference to the progressbar object in the layout and use it like the following:

     ProgressBar progress = (ProgressBar) itemView.findViewById(R.id.progress);
    androidQuery.id(imageView).progress(progress).image(allUrls.get(position), false, true, 0, 0, placeholder, Constants.FADE_IN);