【问题标题】:Progress bar set visiblity using grid view images gallery进度条使用网格视图图像库设置可见性
【发布时间】:2016-09-01 05:34:59
【问题描述】:

大家好,我对进度条有疑问。我试图制作一个画廊视图,所有图像都显示在网格视图中。但问题是,当所有图像加载时,进度条没有消失,请检查代码 我正在使用旋转加载作为进度条

更新

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);
        progressDialog=ProgressDialog.show(mContext,"Loading Data","Please wait.....",false,false);

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


    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();
                    progressDialog.dismiss();
                    return false;
                }

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

                    //rotateLoading.setVisibility(View.INVISIBLE);
                    //rotateLoading.stop();
                    progressDialog.dismiss();

                    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"
    android:visibility="visible"
    app:loading_color="#ffffff"
    android:layout_centerInParent="true"/>        
    </RelativeLayout>
[![Check the image][1]][1]
in the image the picture loads but the progress bar did not stops and invisible. 

请解决问题。

[1]: http://i.stack.imgur.com/2Vqyp.jpg

【问题讨论】:

  • 没人回答我的问题?

标签: android android-studio gridview


【解决方案1】:

更新您的 xml 文件

  <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="invisible"/>

在你的 getView() 方法中,

        rotateLoading.start();
        rotateLoading.setVisibility(View.VISIBLE);
        Glide.with(mContext)
        .load(url)
        .thumbnail(0.5f)
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .fitCenter()
        .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);

【讨论】:

  • 抱歉回复晚了。但错误保持不变。进度条保持可见,
  • 进度条对少数图像不可见,但并非对所有图像都可见。请解决我的问题
  • 你试过用普通的 ProgressBar 代替你的自定义 RotateLoading 吗?
  • 当我使用默认进度条时,它会保留在屏幕上并加载图像
  • 任何特殊原因进度保持在屏幕上并加载图像...
【解决方案2】:

我创建了一个显示图像视图进度的库:PowerfulImageView

导入,添加到gradle这一行

compile 'com.stefanosiano:powerlessimageview:0.3.1'

然后用这个改变你的xml:

<com.stefanosiano.powerfulimageview.PowerfulImageView
    android:layout_width="380dp"
    android:layout_height="380dp"
    android:id="@+id/imageView2"
    app:piv_progress_mode="circular" />

然后将您的 getView 方法更改为:

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

    if (convertView == null) {
        convertView= LayoutInflater.from(mContext).inflate(R.layout.image_gallery,parent,false);
        imageView=(PowerfulImageView)convertView.findViewById(R.id.imageView2);
        imageView.setLayoutParams(new RelativeLayout.LayoutParams(380,480));
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    } else {
        imageView = (PowerfulImageView) convertView.findViewById(R.id.imageView2);
    }
    imageView.changeProgressMode(PivProgressMode.CIRCULA‌​R);
    String url = null;
   url=getItem(position);


    Glide.with(mContext)
            .load(url)
            .thumbnail(0.5f)
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(android.R.drawable.progress_indeterminate_horizontal)
            .centerCrop()
            .crossFade()
            .into(imageView);
    return convertView;
}

如果一切正常,请告诉我:)

【讨论】:

  • 可能我迟到了这个答案:D
猜你喜欢
  • 2014-11-21
  • 2017-11-07
  • 1970-01-01
  • 2011-08-12
  • 2017-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-16
相关资源
最近更新 更多