如何将Picasso的图像加载到简单的View中?

时间:2018-02-12 15:19:39

标签: android picasso

我需要使用Picasso / Glide将图像加载到View中,而不是ImageView.But没有这样的方法。有可能吗?

谢谢大家的回答!

2 个答案:

答案 0 :(得分:0)

使用Picasso,您可以加载Target,如下所示:

Picasso.with(context).load(xyz).into(new Target() {

                @Override
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                     // Load the bitmap into your view
                }

                @Override
                public void onBitmapFailed() {

                }
            });

然后你可以随意使用位图,比如将它加载到自定义视图中。

答案 1 :(得分:0)

如果您不希望Glide将图像直接插入ImageView,那么您可以随时加载图像并使用它执行所需的操作,例如:

Glide.with(getContext())
    .load(uri)
    .asBitmap()
    .into(new SimpleTarget<Bitmap>() {
        @Override
        public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
            // Do anything with the new Bitmap resource you have
        }
    });