我有这个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()
的东西。但是它无法执行我想要的转换。
在第一张照片中,所有内容都按照我想要的方式显示,但只是使用了[[ImageView容器。
在第二张照片中,我使用CircleImageView
容器,它不再像我想要的样子-耳朵在照片中被剪掉了。 [请帮助您,我如何获得正确的结果?NOTE:
我不能使用.load(R.drawable.icon)
,而我不能使用ImageView容器(我可能可以使它以某种方式绕圈)ImageView