1

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

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

谢谢

4

2 回答 2

3

绝对地

  1. 以通常的方式绘制您的小部件,图像旁边的所有文本部分等
  2. 创建一个将加载图像的服务。这是一个很好的教程,其中包括如何从 appwidget 创建和调用服务
  3. 更新您的小部件后调用该服务。传递小部件 ID 和图像 URL
  4. 从缓存或远程在您的服务中加载图像并再次更新您的小部件。瞧,你现在有了
于 2011-12-29T23:29:45.720 回答
1

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

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

于 2012-04-18T02:53:22.023 回答