所以我目前正在研究在毕加索图书馆里用毕加索图书馆替代大量自定义图片加载AsyncTask
的可能性,它看起来很有希望。然而,有一个问题我不完全确定如何使用毕加索解决。加载之前的毕加索图片url查找
在这种情况下,我们正在为音乐曲目下载专辑封面,但是当我们的ListView要显示时,我们只有曲目ID。首先,我们必须根据曲目ID查找专辑封面的URL,然后将其加载到ImageView中。目前我们有一个AsyncTask
,我们在doInBackground()
首先查找图像的URL,然后加载一个Bitmap
,然后粘贴到onPostExecute
。
是否有任何方法使用毕加索进行预先查找,或者我们必须将首次执行查找的中的毕加索调用包装起来(并且感觉它有点违背目的)。
更新:它是如何工作现在:
private class AlbumArtTask extends AsyncTask<String, Bitmap, Bitmap> {
@Override
protected Bitmap doInBackground(String... strings) {
final String id = strings[0];
// This part is what I'm asking for, basically to be able to make an Async
// lookup of the url that will later be used by Picasso
final Uri uri = getAlbumArtUriFromTrackId(id);
// Creating the Bitmap and return it to be used in an ImageView
// This part is handled by Picasso
return bitmap = createBitmapFromUri(uri);
}
@Override
protected void onPostExecute(Bitmap bitmap) {
// load image into ImageView
}
}
更新2:由例如我后
Picasso.with(mContext)
.load(new UriProvider() {
// Get the actual image URI here
public Uri getImageUri() {
return getAlbumArtUriFromTrackId(id);
}
})
// And load it here
.into(mImageView);
什么是查找装货前的目的是什么? – fida1989
是否因为您需要位图用于其他目的?如果是这种情况,可以直接从imageview中获取。 –
预查找是什么意思?您必须从本地存储器显示占位符,或者必须显示其他原始服务器的预查找图像。 –