gpt4 book ai didi

android - 如何将进度条添加到 Picasso 库

转载 作者:太空宇宙 更新时间:2023-11-03 11:56:05 24 4
gpt4 key购买 nike

如何使用此下载照片的代码向 Picasso 库添加进度条

String Url = "link url";
Picasso.with(G.currentActivity).load(Url).into(imageView);

最佳答案

该功能目前不可用。但是,您可以在 ImageView 顶部放置一个进度条,并在下载图像时附加一个回调,然后隐藏进度条。

<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>

然后在你的 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);
}

}

关于android - 如何将进度条添加到 Picasso 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32184156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com