ネットワークからの画像のダウンロードに Picasso ライブラリを使用しています。プログレス ダイアログまたは GIF 画像をプレース ホルダーとして使用できるかどうか疑問に思っています。また、ダウンロードされた実際の画像よりもプレースホルダー画像を小さくする(そして中央に合わせる)方法についてのアイデアはありますか?
サンプルを試してみましたが、うまくいきませんでした。これを機能させた人はいますか?
ネットワークからの画像のダウンロードに Picasso ライブラリを使用しています。プログレス ダイアログまたは GIF 画像をプレース ホルダーとして使用できるかどうか疑問に思っています。また、ダウンロードされた実際の画像よりもプレースホルダー画像を小さくする(そして中央に合わせる)方法についてのアイデアはありますか?
サンプルを試してみましたが、うまくいきませんでした。これを機能させた人はいますか?
次のように Picasso 呼び出しで *.placeholder(R.drawable.image_name)* を使用して、プレースホルダー画像を使用できます。
Picasso.with(context)
.load(imageUrl)
.placeholder(R.drawable.image_name)
プレースホルダー イメージの代わりにプログレス バーを使用する場合は、 .into関数内にコールバックを作成できます。次のようにします。
あなたの見解では:
//create the progressBar here and set it to GONE. This can be your adapters list item view for example
<RelativeLayout
android:id="@+id/myContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
<ImageView
android:id="@+id/myImageView"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_margin="5dp"
android:paddingLeft="60dp"
android:scaleType="centerCrop"></ImageView>
</RelativeLayout>
アダプター/クラスで:
//create a new progress bar for each image to be loaded
ProgressBar progressBar = null;
if (view != null) {
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
}
//get your image view
ImageView myImage = (ImageView) view.findViewById(R.id.myImageView);
//load the image url with a callback to a callback method/class
Picasso.with(context)
.load(imageUrl)
.into(myImage, new ImageLoadedCallback(progressBar) {
@Override
public void onSuccess() {
if (this.progressBar != null) {
this.progressBar.setVisibility(View.GONE);
}
}
});
上記のアダプター/クラス内に、コールバック用の内部クラスを作成します。
private class ImageLoadedCallback implements Callback {
ProgressBar progressBar;
public ImageLoadedCallback(ProgressBar progBar){
progressBar = progBar;
}
@Override
public void onSuccess() {
}
@Override
public void onError() {
}
}
これが理にかなっていることを願っています!
画像のダウンロードまで進行状況ダイアログを実装しましたが、非常にシンプルです。ImageView を相対的なレイアウトで取得し、プログレス ローダーを同じ画像ビューに配置します。以下のコードを適用し、進行状況ダイアログの可視性のみを処理します。
holder.loader.setVisibility(View.VISIBLE);
holder.imageView.setVisibility(View.VISIBLE);
final ProgressBar progressView = holder.loader;
Picasso.with(context)
.load(image_url)
.transform(new RoundedTransformation(15, 0))
.fit()
.into(holder.imageView, new Callback() {
@Override
public void onSuccess() {
progressView.setVisibility(View.GONE);
}
@Override
public void onError() {
// TODO Auto-generated method stub
}
});
}
それが誰かを助けることを願っています!:)
Picasso ライブラリに加えて ProgressBar をセットアップし、リスナーを使用して手動で可視性を管理する必要があります。
私は UniversalImageLoader を使用していますが、Picasso ライブラリは非常に似ているはずです。
private ImageLoadingListener photoSuccess = new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
if(progress != null)
progress.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if(progress != null)
progress.setVisibility(View.GONE);
if(mImage != null)
mImage.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
};