进度条使用网格视图图像库设置可见性 [英] Progress bar set visiblity using grid view images gallery

查看:248
本文介绍了进度条使用网格视图图像库设置可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

更新

  public类ImageAdapter扩展BaseAdapter {
private Context mContext;
ProgressDialog progressDialog;


RotateLoading rotateLoading;
int count;

公共ImageAdapter(Context c){
mContext = c;}

public int getCount(){
return mThumbIds.length;


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


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

//为适配器引用的每个项目创建一个新的ImageView
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,加载数据,请稍候.....,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_horizo​​ntal)
.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();
返回false;
}
$ b $ @覆盖
public boolean onResourceReady(GlideDrawable资源,字符串模型,目标< GlideDrawable>目标,boolean isFromMemoryCache, boolean isFirstResource){

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

返回false;
}
})
.crossFade()
.into(imageView);
返回convertView;
}

//保留数组
中的所有图片public String [] mThumbIds = {
http://idealphotography.biz/wp-content/uploads/ 2016/06 /宽 - 壁纸 - 自然 - 480x800 - 壁纸 - 高清 - 1366x768 - 与壁纸 - 自然 - 480x800 - 下载高清壁纸.jpg,
http://greenywallpapers.com/壁纸/ 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-壁纸 - 大自然 - 480x800 - 关于 - Windows - 7 - 壁纸 - 壁纸 - 大自然 - 480x800 - 下载高清壁纸.jpg,
http://freewallpaper-background.com/wp-content/上传/ 2014/11 / M-3.jpg,
http://naturewallpaperfree.com/mobile/sky/nature-wallpaper-480x800-127-96fbd452.jpg,

};


$ / code $ / pre
$ b $ p这是xml

 <?xml version =1.0encoding =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>
[![检查图片] [1]] [1]
在图片载入的图像中,但进度条并未停止且不可见。

请解决问题。



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


解决方案

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



导入它,添加到gradle这一行

  compile'c​​om .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方法更改为:

  //为适配器引用的每个项目创建一个新的ImageView 
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_horizo​​ntal)
.centerCrop()
.crossFade()
.into(imageView);
返回convertView;
}

让我知道一切是否正常:)


Hello everyone i have an issue with the progress bar. I tried to make a gallery view, all the images shown in grid view.but the issue is that, when all the images is loaded the progress bar did not gone, check the code I am using Rotate-loading as a Progress bar

Updated

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",

};

}

this is 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. 

Please solve the issue.

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

解决方案

I created a library that shows a progress over an imageview: PowerfulImageView.

Import it, adding to gradle this line

compile 'com.stefanosiano:powerlessimageview:0.3.1'

Then change your xml with this:

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

Then change your getView method to:

// 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;
}

Let me know if everything works fine :)

这篇关于进度条使用网格视图图像库设置可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆