@Override public View getConvertView(int position, View convertView, ViewGroup parent) { ImageView imageView; final String imgUrl = dataList.get(position); if (convertView == null) { imageView = new ImageView(mContext); imageView.setLayoutParams(new GridView.LayoutParams(width, width)); // 设置ImageView对象布局 imageView.setAdjustViewBounds(true); // 设置边界对齐 imageView.setScaleType(ImageView.ScaleType.FIT_XY); // 设置刻度的类型 convertView = imageView; } else { imageView = (ImageView) convertView; } ILUtils.disPlay(imageView, UrlUtil.getImageUrl(imgUrl)); return convertView; }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ImageLoader.getInstance() .displayImage( UrlUtil.getImageUrl(mImageUrl), mImageView, new SimpleImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { progressBar.setVisibility(View.VISIBLE); } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { String message = null; switch (failReason.getType()) { case IO_ERROR: message = "下载错误"; break; case DECODING_ERROR: message = "图片无法显示"; break; case NETWORK_DENIED: message = "网络有问题,无法下载"; break; case OUT_OF_MEMORY: message = "图片太大无法显示"; break; case UNKNOWN: message = "未知的错误"; break; } Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(); progressBar.setVisibility(View.GONE); } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { progressBar.setVisibility(View.GONE); mAttacher.update(); } }); }