18

我想知道是否有一种机制可以在使用通用图像加载器加载图像时显示一个旋转的“不确定”进度条来代替图像。

现在,我正在使用 DisplayImageOptions 中的 showStubImage() 选项来显示一个在下载图像时显示“无图像”的图像,但是如果在 ImageView 顶部有一个旋转的不确定 ProgressBar 时,它会非常漂亮。图片正在下载。

4

2 回答 2

55

以供参考

final View imageLayout = inflater.inflate(R.layout.item_pager_image, null);
final ImageView imageView = ...
final ProgressBar spinner = ...

imageLoader.displayImage(images[position], imageView, 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);
    }
});
于 2012-12-01T14:59:03.593 回答
1

我正在发布用于从网络下载图像的网格适配器类代码。您必须使用 oneimageview和 two声明网格布局textviews。将字符串数组传递给适配器。

@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
    // TODO Auto-generated method stub
    LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(activity.LAYOUT_INFLATER_SERVICE);
    //LayoutInflater inflator = activity.getLayoutInflater();
    if(convertView==null)
    {
        view = new ViewHolder();
        convertView = inflater.inflate(R.layout.grid_layout, null);
        view.txtViewTitle = (TextView) convertView.findViewById(R.id.title);
        view.txtViewSubTitle = (TextView) convertView.findViewById(R.id.subTitle);
        view.imgViewFlag = (ImageView) convertView.findViewById(R.id.imageView1);
        convertView.setTag(view);
    }
    else
    {
        view = (ViewHolder) convertView.getTag();
    }

    view.txtViewTitle.setText(listTitle.get(position));
    view.txtViewSubTitle.setText(listSubTitle.get(position));

    //For Picasso
 /*   Picasso.with(parent.getContext())
            .load("http://www.radioarpan.com/upload_images/138630281911.jpg")
            .placeholder(R.mipmap.paceholder)
            .error(R.mipmap.error_page_logo)
            .noFade().resize(125,165)
            .centerCrop()
            .into(view.imgViewFlag);*/



    ImageLoader imageLoader = ImageLoader.getInstance();
    DisplayImageOptions.Builder options = new DisplayImageOptions.Builder().cacheInMemory(true)
            .cacheOnDisc(true).resetViewBeforeLoading(true)
            .showImageForEmptyUri(R.mipmap.paceholder)
            .showImageOnFail(R.mipmap.error_page_logo);


    final ProgressBar spinner =  new ProgressBar(activity, null, android.R.attr.progressBarStyleSmall);
//download and display image from url
      imageLoader.displayImage("http://www.radioarpan.com/upload_images/138630281911.jpg", view.imgViewFlag,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);
       }
   });
于 2015-06-10T07:13:43.880 回答