1
有没有办法将图像从互联网延迟加载到远程视图中。appwidget中的lazyload图像
remoteView.setImageViewBitmap(R.id.image, UrlUtils.loadBitmap(bitmapUrl));
我使用此功能,但它在很短的时间内阻止了我的小部件。
public static Bitmap loadBitmap(String url) {
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(getPageInputStream(url));
final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream);
Utils.copy(in, out);
out.flush();
final byte[] data = dataStream.toByteArray();
BitmapFactory.Options options = new BitmapFactory.Options();
// options.inSampleSize = 1;
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,
options);
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
感谢
如果没有这两个更新之间再次更新只小部件。在这种情况下,您将失去新的窗口小部件状态 – Maxim
还有一件事,您需要在将图像展示到窗口小部件之前向下取样您的图像,否则您将被“RemoteViews用于窗口小部件更新超出最大位图内存使用情况例外”的冲击。 – TilalHusain
@Bostone如果你需要加载appWidget中的listView的图像?根据我所看到的,这是在“getViewAt”(在BG线程上运行)中完成的,但在加载图像之前无法更新其余行(文本等),这太糟糕了...... –