如何将进度条添加到毕加索库 [英] How to add progress bar to Picasso library
本文介绍了如何将进度条添加到毕加索库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用此代码向Picasso库添加进度条以下载照片
How can you add a progress bar to Picasso library with this code for downloading photos
String Url = "link url";
Picasso.with(G.currentActivity).load(Url).into(imageView);
推荐答案
该功能目前不可用.但是,您可以在图像视图的顶部放置一个进度条,并在下载图像时附加一个回叫,然后隐藏进度条.
That feature is not available at the moment. However, you can put a progress bar on top of the imageview and attach a call back for when the image is downloaded then hide the progress bar.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:scaleType="center"/>
<ProgressBar
style="@android:style/Widget.Holo.Light.ProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
</RelativeLayout>
然后在您的活动中这样的事情
then something like this in your activity
import com.squareup.picasso.Callback;
public class MyActivity extends Activity implements Callback {
private View loaderView;
private ImageView imageView;
// ...
private synchronized void loadImage(Uri uri)
{
Picasso.with(this).load(uri)
.error(R.drawable.ic_error)
.placeholder(R.drawable.ic_placeholder)
.resize(getImageWidth(), getImageHeight())
// passes this object as it's callback when image is loaded
.centerCrop().into(imageView, this);
}
@Override
public void onSuccess()
{
// hide the loader and show the imageview
loaderView.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);
}
@Override
public void onError()
{
// hide the loader and show the imageview which shows the error icon already
loaderView.setVisibility(View.GONE);
imageView.setVisibility(View.VISIBLE);
}
}
这篇关于如何将进度条添加到毕加索库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文