0

我有一个自定义的 Gridview。在我的适配器中使用 AQuery 完成异步图像下载。图像已正确下载,但在某些情况下会发生错误,因此图像视图背景完全变白。我想设置该错误图像。

现在这是我在 gridView() 中的适配器的代码:

try{
            String[] tmp_arr_thumb_img = prodItems.get(holder.position).getprod_image().split(global.split_seprator);
            //String imageID = tmp_arr_thumb_img[0];
            String thumbImg = tmp_arr_thumb_img[1];

            if (aQuery.shouldDelay(holder.position, convertView, parent, global.GLOBAL_UPLOADED_PHOTOS_URL + thumbImg)){
                aQuery.id(holder.imageView).image(R.drawable.no_image);
            }else{
                aQuery.id(holder.imageView)
                        .image(global.GLOBAL_UPLOADED_PHOTOS_URL + thumbImg,true,true,200,0, new BitmapAjaxCallback(){
                            @Override
                            protected void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {

                                iv.setImageBitmap(bm);
                            }
                        }.animation(AQuery.FADE_IN));
            }
        }catch (OutOfMemoryError err){
            err.printStackTrace();
        }
4

2 回答 2

0

请使用占位符图像更新您的代码

aQuery.id(holder.imageView)
                    .image(global.GLOBAL_UPLOADED_PHOTOS_URL + thumbImg,true,true,200,R.drawable.placeholder, new BitmapAjaxCallback(){
                        @Override
                        protected void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {

                            iv.setImageBitmap(bm);
                        }
                    }.animation(AQuery.FADE_IN));
于 2016-07-15T06:47:47.027 回答
0

If we are not able to load the image, use a default image (R.drawable.default_image)

String imageUrl = "http://www.vikispot.com/z/images/vikispot/android-w.png";
aq.id(R.id.image1).image(imageUrl, true, true, 0, R.drawable.default_image);

Make image view "invisible" if image failed to load

imageUrl = "http://a.b.com/invalid.jpg"; 
aq.id(R.id.image1).image(imageUrl, true, true, 0, AQuery.INVISIBLE);

Make image view "gone" if image failed to load

aq.id(R.id.image1).image(imageUrl, true, true, 0, AQuery.GONE);
于 2016-07-15T07:01:29.750 回答