无法在CircleImageView中调整图片大小

时间:2020-05-08 08:14:09

标签: android imageview android-imageview picasso android-glide

我有这个XML:

<de.hdodenhof.circleimageview.CircleImageView
    android:src="@drawable/ic_kitty_superhero"
    android:id="@+id/userAvatar"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_gravity="center"
    android:layout_marginBottom="16dp"
    app:civ_border_color="@android:color/white" // just to show you wrong result
    app:civ_border_width="1dp" />

和此扩展功能以加载图像:

fun ImageView.loadImage(context: Context, url: String) {
    val resourceID = context.resources.getIdentifier(url, "drawable", context.packageName)
    if (resourceID != 0) { // if it's an image from drawable folder
        Glide.with(context)
            .load(resourceID)
            .fitCenter()
            .into(this)
    } else {
        Picasso.with(context)
            .load(url)
            .fit()
            .centerInside()
            .into(this)
    }
}

由于毕加索不知道如何使用resourceID,因此我需要使用Glide或类似的this.setImageResource()。但是它无法执行我想要的转换。

enter image description here enter image description here

在第一张照片中,一切看起来都和我想要的一样,但是只是使用了 ImageView 容器。

在第二张照片中,我使用了 CircleImageView 容器,它的外观不再像我想要的那样-在照片中剪裁了耳朵。

请,您能帮我吗,我如何得到正确的结果?

注意::我不能使用.load(R.drawable.icon),而我不能使用ImageView容器(如果让它以某种方式旋转)

0 个答案:

没有答案
相关问题