在毕加索中加载图像时如何使用进度条? [英] how to use progressbar when loading image in picasso?
问题描述
我希望onStart()
方法使用毕加索从服务器加载图像,并且我想显示进度条,直到完全下载照片为止
这是我的代码:
I want onStart()
method to load image from server using picasso and I want to show a progress bar until the photos are fully downloaded
Here is my code:
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
Picasso.with(context).load(imageLoad)
.placeholder(R.id.progressBarDetails)
.error(R.drawable.friend_request).noFade().resize(200, 200)
.into(avatarImage, new Callback() {
@Override
public void onError() {
// TODO Auto-generated method stub
}
@Override
public void onSuccess() {
// TODO Auto-generated method stub
progressbar.setVisibility(View.GONE);
}
});
Picasso.with(this).load(imageLoad).into(target);
}
OnFinished a = new OnFinished() {
@Override
public void onSendFinished(IntentSender IntentSender, Intent intent,
int resultCode, String resultData, Bundle resultExtras) {
// TODO Auto-generated method stub
intent = new Intent(getApplicationContext(), Map.class);
}
};
private Target target = new Target() {
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
new Thread(new Runnable() {
@Override
public void run() {
File file = new File(Environment
.getExternalStorageDirectory().getPath()
+ "/actress_wallpaper.jpg");
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 75, ostream);
ostream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
推荐答案
我还没有测试您的代码,但是即使可以工作,ImageView中也没有加载文件actress_wallpaper.jpg
.在文档中,它说
I haven't tested your code but even if that works, the file actress_wallpaper.jpg
isn't loaded in the ImageView. In the docs, it says
实现此类的对象必须具有
Object.equals(Object)
和Object.hashCode()
的有效实现,才能在内部正确存储.
Objects implementing this class must have a working implementation of
Object.equals(Object)
andObject.hashCode()
for proper storage internally.
尝试一下:
File file = new File(pathToFile);
Picasso.with(context)
.load(file)
.into(imageView, new Callback() {
@Override
public void onSuccess() {
progressbar.setVisibility(View.GONE);
}
});
警告我还没有测试我的代码.
be warned I haven't tested my code.
更新:
我尝试过版本2.3.2和2.3.3,似乎有一个问题 https ://github.com/square/picasso/issues/539
I have tried version 2.3.2 and 2.3.3, it seems like that there's an issue https://github.com/square/picasso/issues/539
这篇关于在毕加索中加载图像时如何使用进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!