Show an “Loading…” image while background loading of image with Picasso

℡╲_俬逩灬. 提交于 2019-12-03 14:09:15

问题


I am using Picasso for background loading of images (list view and ImagePager). I can set loading image and errorimage with Picasso, but I am unable to show a "loading in progress" Image during background loading.

Has anybody an idea how to get this done? In my PagerAdapter Class I have the following method:

        @Override
public Object instantiateItem(ViewGroup container, int position) {
    ImageView imageView = new ImageView(context);
    int padding = context.getResources().getDimensionPixelSize(R.dimen.padding_medium);
    imageView.setPadding(padding, padding, padding, padding);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    // Set default Image before loading real image
    imageView.setImageResource(R.drawable.img_def);

    imageView.setId(imgViewId);
    imageView.setClickable(true);
    imageView.setOnClickListener(this);
    ((ViewPager) container).addView(imageView, 0);

    // Set default Image before loading real image
    Picasso.with(context).load(R.drawable.img_def).into(imageView);

    // Load real image with Picasso and show error image if failed
    Picasso.with(context).load(GalImgUrls[position]).error(R.drawable.no_img).into(imageView);

    return imageView;
}

However, it does not show the "loading..." image. Any solutions/ideas?

Thanks!


回答1:


Looks like I found a solution myself. Use "placeholder" image:

       Picasso.with(context).load(tnu).error(R.drawable.no_img).placeholder(R.drawable.img_def).into(holder.immoPic);

Works like charm....



来源:https://stackoverflow.com/questions/22655245/show-an-loading-image-while-background-loading-of-image-with-picasso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!