Picasso 的 Target 和 centerCrop() 和 fit() [英] Picasso's Target and centerCrop() and fit()

查看:51
本文介绍了Picasso 的 Target 和 centerCrop() 和 fit()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器上有一张图片,我想在我的 Android 客户端上使用 Picasso 显示它.我想在 Picasso 上加载图像时添加默认图像,因此我使用 Target 如下:

I have an image on my server and I want to display it using Picasso on my Android client. I want to add a default image when the image is loading on Picasso so I am using Target as follows:

Picasso.with(UserActivity.this).load(imageUri.toString()).transform(new RoundedTransformation(500, 1)).into(
new Target() {
    @Override
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
        userPic.setImageBitmap(bitmap);
    }

    @Override
    public void onBitmapFailed(Drawable drawable) {
        userPic.setImageBitmap(defaultDrawable);
    }

    @Override
    public void onPrepareLoad(Drawable drawable) {
        userPic.setImageBitmap(defaultDrawable);
    }
});

我想要 centerCrop()fit() 这个图像,但它给了我一个错误,它告诉我我不能将它们与 Target 一起使用.无论如何可以在毕加索上使用这些功能吗?为什么他们不允许 Target 使用这两个函数?

I want to centerCrop() and fit() this image but it gives me an error and it tells me that I cant use them with Target. Is there anyway to use these features on Picasso? Why don't they allow these two functions with Target?

推荐答案

你不需要使用 Target 来实现你的目标.

You don't need to use Target to accomplish your goal.

旁注,我不确定您是否可以同时使用 fit()centerCrop().

Side note, I am not certain that you can actually use both fit() and centerCrop() together.

请参阅此示例:

Picasso.with(context)
    .load(url) // Equivalent of what ends up in onBitmapLoaded
    .placeholder(R.drawable.user_placeholder) // Equivalent of what ends up in onPrepareLoad
    .error(R.drawable.user_placeholder_error) // Equivalent of what ends up in onBitmapFailed
    .centerCrop()
    .fit()
    .into(imageView);

这篇关于Picasso 的 Target 和 centerCrop() 和 fit()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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