appwidget中的lazyload图像

时间:2011-09-08 13:55:50

标签: android android-appwidget android-imageview remoteview android-lazyloading

有没有办法将图像从互联网延迟加载到远程视图中。

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;
}

由于

2 个答案:

答案 0 :(得分:3)

绝对

  1. 以常规方式绘制小部件,图像旁边的所有文本部分等
  2. 创建一个将加载图片的服务。 Here's good tutorial,其中包括如何从appwidget创建和调用服务
  3. 更新小部件后,请致电该服务。传递窗口小部件ID和图像URL
  4. 从缓存中加载图片或远程加载服务中的图片并再次更新窗口小部件。瞧,你现在有了

答案 1 :(得分:1)

尝试使用android-query lib进行lazyload加载。

https://code.google.com/p/android-query/#Image_Loading