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線程上運行)中完成的,但在加載圖像之前無法更新其餘行(文本等),這太糟糕了...... –