Android appwidget中的懒散加载图像
有没有办法将图像从internet懒散地加载到remoteview中Android appwidget中的懒散加载图像,android,android-appwidget,android-imageview,remoteview,android-lazyloading,Android,Android Appwidget,Android Imageview,Remoteview,Android Lazyloading,有没有办法将图像从internet懒散地加载到remoteview中 remoteView.setImageViewBitmap(R.id.image, UrlUtils.loadBitmap(bitmapUrl)); 我使用这个函数,但它在很短的时间内阻塞了我的小部件 public static Bitmap loadBitmap(String url) { Bitmap bitmap = null; InputStream in = null; BufferedOu
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;
}
非常感谢
尝试android查询库来加载lazyload
尝试android查询库加载懒虫负载
如果在这两次更新之间没有再次更新widget。在这种情况下,您将丢失新的窗口小部件状态还有一件事,您需要在将图像显示到窗口小部件之前对其进行下采样,否则您将被
RemoteView所困扰,因为窗口小部件更新超过了最大位图内存使用量
异常。@Bostone如果您需要在appWidget中加载列表视图的图像,该怎么办?据我所见,这是在“getViewAt”(在BG线程上运行)中完成的,但在加载图像之前无法更新行的其余部分(文本等),这太糟糕了……如果在这两次更新之间没有再次更新小部件的话。在这种情况下,您将丢失新的窗口小部件状态还有一件事,您需要在将图像显示到窗口小部件之前对其进行下采样,否则您将被RemoteView所困扰,因为窗口小部件更新超过了最大位图内存使用量
异常。@Bostone如果您需要在appWidget中加载列表视图的图像,该怎么办?据我所见,这是在“getViewAt”(在BG线程上运行)中完成的,但在加载图像之前无法更新行的其余部分(文本等),这太糟糕了。。。