在android中使用picasso在gridview中同时显示多张图片
Display multiple images at the same time using picasso into gridview in android
请帮助我 this.I 试过这段代码,但它显示不同的图像 times.I 需要同时显示所有图像 time.thank 你的帮助
Picasso.with(getContext()).load(result.thumListUrl).fetch();
Picasso
.with(getContext())
.load(result.thumListUrl)
.networkPolicy(NetworkPolicy.OFFLINE)
.fit()
.into(img, new Callback() {
@Override
public void onSuccess() {
Log.d("Picasso", "Image loaded from cache>>>" + result.thumListUrl);
}
@Override
public void onError() {
Log.d("Picasso", "Try again in ONLINE mode if load from cache is failed");
Picasso.with(getContext()).load(result.thumListUrl).fit().into(img, new Callback() {
@Override
public void onSuccess() {
Log.d("Picasso", "Image loaded from web>>>" + result.thumListUrl);
}
@Override
public void onError() {
Log.d("Picasso", "Failed to load image online and offline, make sure you enabled INTERNET permission for your app and the url is correct>>>>>>>" + result.thumListUrl);
}
});
}
});
从 URL
加载 images
并让它在不同时间获取数据时加载,而不是隐藏 imageview
或用占位符 imageview
覆盖它直到所有 images
都加载完毕。
在片段中
private int loadedImages = 0;
private int numberOfImagesToBeLoaded = 2;
ArrayList<ImageView> images = new ArrayList<>();
addImageUsingPicasso(url1,img1);
addImageUsingPicasso(url2,img2);
public void addImageUsingPicasso(String url,ImageView img){
images.add(img);
private Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
img.setImageBitmap(bitmap);
loadedImages++;
if(loadedImages == numberOfImagesToBeLoaded) { //<--- All images are loaded
showImages();
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
loadedImages++;
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
}
Picasso.with(getContext()).load(url).into(target);
}
private void showImages(){
for(ImageView image : images){
image.setVisibility(View.VISIBLE);
}
}
请帮助我 this.I 试过这段代码,但它显示不同的图像 times.I 需要同时显示所有图像 time.thank 你的帮助
Picasso.with(getContext()).load(result.thumListUrl).fetch();
Picasso
.with(getContext())
.load(result.thumListUrl)
.networkPolicy(NetworkPolicy.OFFLINE)
.fit()
.into(img, new Callback() {
@Override
public void onSuccess() {
Log.d("Picasso", "Image loaded from cache>>>" + result.thumListUrl);
}
@Override
public void onError() {
Log.d("Picasso", "Try again in ONLINE mode if load from cache is failed");
Picasso.with(getContext()).load(result.thumListUrl).fit().into(img, new Callback() {
@Override
public void onSuccess() {
Log.d("Picasso", "Image loaded from web>>>" + result.thumListUrl);
}
@Override
public void onError() {
Log.d("Picasso", "Failed to load image online and offline, make sure you enabled INTERNET permission for your app and the url is correct>>>>>>>" + result.thumListUrl);
}
});
}
});
从 URL
加载 images
并让它在不同时间获取数据时加载,而不是隐藏 imageview
或用占位符 imageview
覆盖它直到所有 images
都加载完毕。
在片段中
private int loadedImages = 0;
private int numberOfImagesToBeLoaded = 2;
ArrayList<ImageView> images = new ArrayList<>();
addImageUsingPicasso(url1,img1);
addImageUsingPicasso(url2,img2);
public void addImageUsingPicasso(String url,ImageView img){
images.add(img);
private Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
img.setImageBitmap(bitmap);
loadedImages++;
if(loadedImages == numberOfImagesToBeLoaded) { //<--- All images are loaded
showImages();
}
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
loadedImages++;
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
}
Picasso.with(getContext()).load(url).into(target);
}
private void showImages(){
for(ImageView image : images){
image.setVisibility(View.VISIBLE);
}
}