使用ImageLoader设置圆角时无效或者干脆图片不显示

在项目中使用ImageLoader来加载图片,现在有个需求是,这个视频封面需要微微的有圆角。
我的代码刚开始时这样写的:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.wjq.myimageloaderdemo.MainActivity">

    <TextView
        android:id="@+id/iv_load"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:text="点击用ImageLoader加载图片"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.293" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/ic_launcher"
        app:layout_constraintVertical_bias="0.498"/>

</android.support.constraint.ConstraintLayout>

对于ImagerLoader加载图片时默认的设置代码如下:

        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.search_video_default) // 设置图片下载期间显示的图片
                .showImageForEmptyUri(R.mipmap.search_video_default) // 设置图片Uri为空或是错误的时候显示的图片
                .showImageOnFail(R.mipmap.search_video_default) // 设置图片加载或解码过程中发生错误显示的图片
                .cacheInMemory(true) // 设置下载的图片是否缓存在内存中
                .cacheOnDisk(true) // 设置下载的图片是否缓存在SD卡中
                .displayer(new RoundedBitmapDisplayer(20))//这一句就是设置让ImageLoader加载的图片有圆角的地方
                .build(); // 构建完成

结果就是,ImageLoader什么也没有加载出来。我还检查好久,看看是不是我哪里写错了。直到找到原因前,我一直都认为是我哪里写错了。但检查好几遍发现。有区别的地方就是:

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@mipmap/ic_launcher"
        app:layout_constraintVertical_bias="0.498"/>

别人的写法,ImageView有明确的宽高,而我是wrap_content,结果我就试着随便写了个宽高,真的他妈的能显示出来了,圆角也有了。具体什么原因,得去看ImageLoader的源码了,不过我先记下来。源码以后有时间再看。

总结:如果使用使用ImageLoader给ImageView加载的图片设置圆角时无效或者干脆图片不显示,可能的原因就是没有给ImageView设置具体的layout_width和layout_height的值。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值