【发布时间】:2020-05-08 08:14:09
【问题描述】:
我有这个 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)
}
}
由于 Picasso 不知道如何使用 resourceID,我需要使用 Glide 或类似 this.setImageResource() 的东西。但它无法执行我想要的转换。
在第一张照片中,一切看起来都如我所愿,但它只是使用了 ImageView 容器。
在第二张照片中,我使用了 CircleImageView 容器,但它看起来不再像我想要的那样 - 照片中的耳朵被裁剪了。
请您帮帮我,我怎样才能得到正确的结果?
注意:我不能使用.load(R.drawable.icon),并且我不能使用 ImageView 容器(如果可以的话,我可能可以以某种方式圈)
【问题讨论】:
-
尝试添加 Android:scaleType: fitXY
-
@CodeREDInnovations,“ScaleType 始终为 CENTER_CROP,如果您尝试更改它,您会遇到异常”-来自here的信息
标签: android imageview android-imageview picasso android-glide