我使用
从rss说明加载图像String description2 = des.get(position).toString();
Spanned description = Html.fromHtml(description2, new ImageGetter() {
@Override
public Drawable getDrawable(String source) {
Drawable d = null;
try {
InputStream src = imageFetch(source);
d = Drawable.createFromStream(src, "src");
if(d != null){
d.setBounds(0,0,d.getIntrinsicWidth(),
d.getIntrinsicHeight());
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return d;
}
public InputStream imageFetch(String source)
throws MalformedURLException,IOException {
URL url = new URL(source);
Object o = url.getContent();
InputStream content = (InputStream)o;
// add delay here (see comment at the end)
return content;
}
},null);
如何将它们放入AsyncTask中,以便在图像下载之前获得进度条?谢谢!
答案 0 :(得分:0)
您可以查看此tutorial,它会从网上下载图片并使用进度条。所有在AsyncTask中完成,并且完整的源代码可用。
答案 1 :(得分:0)
您可以使用WebImageView中的generic-store-for-android {}
改编自droid-fu项目。
这是一个示例用法;
- >在你的布局中定义
<com.wareninja.opensource.droidfu.widgets.WebImageView
android:id="@+id/img_fbProfilePic"
android:visibility="visible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
- &GT;设置要加载的网址
WebImageView fbProfilePic = (WebImageView) this.findViewById(R.id.img_fbProfilePic);
fbProfilePic.setImageUrl("http://graph.facebook.com/100001789213579/picture");
fbProfilePic.loadImage();