如何使用此代码下载照片,为Picasso库添加进度条
String Url = "link url";
Picasso.with(G.currentActivity).load(Url).into(imageView);
Run Code Online (Sandbox Code Playgroud)
目前暂不提供该功能.但是,您可以在图像视图的顶部放置一个进度条,并在下载图像时附加回调,然后隐藏进度条.
<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>
Run Code Online (Sandbox Code Playgroud)
然后在你的活动中这样的事情
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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7565 次 |
| 最近记录: |