Android的毕加索 - 占位符和错误的图像造型 [英] Android Picasso - Placeholder and Error image styling

查看:164
本文介绍了Android的毕加索 - 占位符和错误的图像造型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是毕加索库从网络上下载图像。我不知道我是否可以使用进度对话框或GIF图像占位符?如何使占位形象是小(适合在中心),比下载的实际形象也什么想法?

I'm using Picasso library for image downloading from the network. I just wonder whether I can use a progress dialog or a GIF image as a place holder? Also any idea on how to make place holder image to be smaller (and fit in centre) than the actual image that is downloaded?

我试着去通的样品,但没有运气。在这里任何一个谁得到了这个工作?

I tried going thru the samples but no luck. Any one here who got this to work?

推荐答案

您可以通过使用* .placeholder(R.drawable.image_name)*在毕加索的呼叫像使用一个占位符图像:

You can use a placeholder image by using the *.placeholder(R.drawable.image_name)* in your Picasso call like:

Picasso.with(context)
       .load(imageUrl)
       .placeholder(R.drawable.image_name)

如果你想使用一个占位符图像的进度条,而不是你可以创建的。走进的函数中的回调

。做类似下面的内容:

If you want to use a progress bar instead of a placeholder image you can create a callback inside the .into function. Do something similar to the following:

您的观点:

//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() {

    }
}

希望这是有道理的!

Hope this makes sense!

这篇关于Android的毕加索 - 占位符和错误的图像造型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆