我相信这是微不足道的,但我无法让它发挥作用 我想在图库元素(ImageViews)中显示默认图像,同时从网络中获取实际图像 现在,没有显示ImageView的图像尚未到达。一旦到达,立即显示 我尝试的是在ImageView实例化后立即调用它的setImageResource函数:
final ImageView i = new ImageView(mContext);
i.setImageResource(R.drawable.loading);
但它似乎不起作用。下面是完整的getView()函数 任何帮助表示赞赏 感谢。
public View getView(int position, View convertView, ViewGroup parent) {
final ImageView i = new ImageView(mContext);
i.setImageResource(R.drawable.loading);
// if the drawbale is in the buffer - fetch it from there
Drawable bufferedImage = DataManager.getInstance().getImagesBuffer()[position];
if (bufferedImage != null){
i.setImageDrawable(bufferedImage);
BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
drawable.setAntiAlias(true);
}
// if drawable is not in buffer - fetch it from the net via AsyncImageLoader
else
{
String imageUrl = DataManager.getInstance().getImageBufferInstance().getImageUrl(position);
Drawable downloadedImage = AsyncImageLoader.getInstance().loadDrawable(imageUrl, new ImageCallback() {
public void imageLoaded(Drawable imageDrawable, String imageUrl) {
if (imageDrawable == null)
{
imageDrawable = getResources().getDrawable(R.drawable.icon);
}
i.setImageDrawable(imageDrawable);
BitmapDrawable drawable = (BitmapDrawable) i.getDrawable();
drawable.setAntiAlias(true);
}
});
i.setImageDrawable(downloadedImage);
}
i.setLayoutParams(new CoverFlow.LayoutParams(Utils.getInstance().getScreenWidth() / 2,
Utils.getInstance().getScreenHeight() / 2));
i.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
return i;
}
答案 0 :(得分:0)
修复缩进...如果我正确读取,你只是在你的(未显示的)AsyncImageLoader的imageLoaded回调中设置临时可绘制图标,我认为这意味着它只是在图像之后设置下载并立即用下载的图像覆盖。尝试将占位符设置代码移动到回调之外的else块中。