使用ImageLoader设置圆角时无效或者干脆图片不显示
2017-05-15 20:03
776 查看
在项目中使用ImageLoader来加载图片,现在有个需求是,这个视频封面需要微微的有圆角。
我的代码刚开始时这样写的:
对于ImagerLoader加载图片时默认的设置代码如下:
结果就是,ImageLoader什么也没有加载出来。我还检查好久,看看是不是我哪里写错了。直到找到原因前,我一直都认为是我哪里写错了。但检查好几遍发现。有区别的地方就是:
别人的写法,ImageView有明确的宽高,而我是wrap_content,结果我就试着随便写了个宽高,真的他妈的能显示出来了,圆角也有了。具体什么原因,得去看ImageLoader的源码了,不过我先记下来。源码以后有时间再看。
总结:如果使用使用ImageLoader给ImageView加载的图片设置圆角时无效或者干脆图片不显示,可能的原因就是没有给ImageView设置具体的layout_width和layout_height的值。
我的代码刚开始时这样写的:
<?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的值。
相关文章推荐
- 使用ImageLoader显示圆角图片、圆形图片、加载drawable的BUG
- Imageloader 使用指南之 显示圆角图片
- Imageloader四种图片显示(圆形,淡入,圆角,修饰)使用
- Imageloader基本使用(显示图片设置)
- 关于ImageLoader 设置圆角参数后不显示图片的问题
- Android 使用自定义Drawable 设置圆角矩形或者圆形图片
- 设置SDWebImage中maxCacheSize动态管理图片内存缓存大小无效。maxCacheSize和maxMemoryCost的定义和使用。
- 动态设置Button、ImageView等组件在不同状态下的背景/前景显示效果。 扩展下的话可以前景/背景的显示效果可以使用网络图片。
- 单纯的使用一张图片,设置为 SplashScreen 的方式我已经使用过了,是有效果的,但是现在我想更进一步的显示出当前程序的状态,如正在初始化设备,这类的状态
- 问题: 在使用thinkphp自带分页类时,在设置尾页显示的最后一页时,用setConfig(“last”,”尾页”)来设置样式,发现无效。
- 关于如何使用websocket 接收并显示图片或者操作二进制
- [置顶] 使用ImageLoader加载网络图片时,如何获取加载进度,如何设置进度条
- ios移动开发navigationItem自带的返回按钮设置成自定义图片或者不显示父视图的标题文字
- 给图片设置圆角 使用CALayer
- UIButton设置图片后显示的图片不使用@3x规格
- Imageloader四种图片显示(圆形,淡入,圆角,修饰)代码分析
- 关于如何使用websocket 接收并显示图片或者操作二进制
- 自定义View—使用clipPath或者BitmapShader实现圆角图片
- 关于js设置标签样式来显示图片背景无效的解决方案
- 关于如何使用websocket 接收并显示图片或者操作二进制