使用滑行在网格视图中加载图像时如何隐藏进度条

时间:2016-09-21 20:33:55

标签: android gridview android-gallery android-glide

我是一名新的Android开发人员。我正在制作一个包含图片列表的网格视图。我正在使用滑动来加载图像视图中的图像,但问题是当图像加载成功时,进度条没有消失。这是我的代码:

public class ImageAdapter extends BaseAdapter {
private Context mContext;
ProgressDialog progressDialog;


RotateLoading rotateLoading;
int count;

public ImageAdapter(Context c) {
mContext = c;}

public int getCount() {
return mThumbIds.length;

}

@Override
public String getItem(int position) {
return mThumbIds[position];
}


public long getItemId(int position) {
return 0;
} 

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;

if (convertView == null) {
    convertView=        LayoutInflater.from(mContext).inflate(R.layout.image_gallery,parent,false);
    imageView=(ImageView)convertView.findViewById(R.id.imageView2);
    imageView.setLayoutParams(new RelativeLayout.LayoutParams(380,480));
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

    rotateLoading=  (RotateLoading)convertView.findViewById(R.id.rotateloading);


} else {
    imageView = (ImageView) convertView.findViewById(R.id.imageView2);
    **rotateLoading=  (RotateLoading)convertView.findViewById(R.id.rotateloading);**
}
String url = null;
url=getItem(position);

**rotateLoading.start();**
Glide.with(mContext)
        .load(url)
        .thumbnail(0.5f)
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .placeholder(android.R.drawable.progress_indeterminate_horizontal)
        .centerCrop()
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                rotateLoading.setVisibility(View.INVISIBLE);
                rotateLoading.stop();
                return false;
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {

                rotateLoading.setVisibility(View.INVISIBLE);
                rotateLoading.stop();

                return false;
            }
        })
        .crossFade()
        .into(imageView);
return convertView;
}

// Keep all Images in array
public String[] mThumbIds = {
    "http://idealphotography.biz/wp-content/uploads/2016/06/Wide-wallpaper-nature-480x800-In-Wallpaper-HD-1366x768-with-wallpaper-nature-480x800-Download-HD-Wallpaper.jpg",
    "http://greenywallpapers.com/wallpapers/10/275050-nature-wallpapers-720x1280.jpg",
    "https://idealphotography.biz/wp-content/uploads/2016/06/Best-wallpaper-nature-480x800-For-Wallpapers-Image-with-wallpaper-nature-480x800-Download-HD-Wallpaper.jpg",
    "https://idealphotography.biz/wp-content/uploads/2016/06/Best-wallpaper-nature-480x800-In-Windows-Wallpaper-Themes-with-wallpaper-nature-480x800-Download-HD-Wallpaper.jpg",
    "https://idealphotography.biz/wp-content/uploads/2016/06/Highres-wallpaper-nature-480x800-About-Windows-7-Wallpaper-with-wallpaper-nature-480x800-Download-HD-Wallpaper.jpg",
    "http://freewallpaper-background.com/wp-content/uploads/2014/11/M-3.jpg",
    "http://naturewallpaperfree.com/mobile/sky/nature-wallpaper-480x800-127-96fbd452.jpg",

};

}

XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="380dp"
android:layout_height="380dp"
android:id="@+id/imageView2"
/>
<com.victor.loading.rotate.RotateLoading
android:id="@+id/rotateloading"
android:layout_width="80dp"
android:layout_height="80dp"
app:loading_width="5dp"
app:loading_color="#ffffff"
android:layout_centerInParent="true"
android:visibility="visible"/>       
</RelativeLayout>

我也使用了默认进度条,但它也没有消失。

0 个答案:

没有答案