java - Glide 过渡中断变换

标签 java android kotlin android-glide

我想用占位符过渡在我的图像上制作圆角。
(其他SO答案是关于没有翻译的圆角,不要标记重复)

此代码使圆角:

Glide
    .with(itemView.context)
    .load(imgUrl)
    .transform(CenterCrop(), RoundedCorners(radius))
    .placeholder(R.drawable.default_image)
    .into(itemView.image)

这段代码没有成功(当我添加转换时):
Glide
    .with(itemView.context)
    .load(imgUrl)
    .transform(CenterCrop(), RoundedCorners(radius))
    .placeholder(R.drawable.default_image)
    .transition(DrawableTransitionOptions().crossFade()) // There
    .into(itemView.image)

我究竟做错了什么?

UPD:图像 xml:
<ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:contentDescription="@string/cd_event_image"
    android:scaleType="fitCenter"
    tools:srcCompat="@drawable/default_image" />

最佳答案

使用圆角形状占位符代替图像解决(占位符的矩形隐藏圆角):

Glide
    .with(itemView.context)
    .load(imgUrl)
    .placeholder(R.drawable.shape_rounded)
    .transition(DrawableTransitionOptions().crossFade())
    .transform(RoundedCorners(radius))
    .into(itemView.image)
圆形:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="@dimen/event_corners_radius" />
    <solid android:color="@color/rdColorMainBackground"/>
</shape>

关于java - Glide 过渡中断变换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58746342/

相关文章:

java - 从多维数组中删除行

android - 如何在 1 个 Playstore 项目中上传 2 个不同风格的应用程序

arrays - Kotlin:字符串到键值的数组

java - Hibernate 逆向工程未生成正确的域代码 STS

javascript - 如何在 Angular 7 中下载 PDF?

android - Eclipse在开发android应用程序时卡住了很多,也是模拟器

android - 开始 Android 编程 - 向应用程序添加广告

java - Codenameone CSS自定义字体需要花费时间才能呈现

KotlinJvmOptions useIR 选项

java - @Resource 在 Spring 中不起作用?