使用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的值。

猜你喜欢

转载自blog.csdn.net/u014434080/article/details/72190835