我有一个listview
with CompoundDrawable
,复合中的图像drawable
需要从网络加载。如何CompoundDrawable
从 URL 加载图像。我认为我可以从 URL 中获取位图图像,将其转换为 Drawable,然后将其加载到 CompoundDrawable 中。像这样
public static Drawable drawableFromUrl(String url) throws IOException {
Bitmap x;
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.connect();
InputStream input = connection.getInputStream();
x = BitmapFactory.decodeStream(input);
return new BitmapDrawable(x);
}
有更好的方法吗?我可以直接做到这一点而不从 URL 获取位图然后将位图转换为可绘制的吗?