glide加载造成的一个内存抖动问题
2020-04-11 本文已影响0人
朱_c713
项目需求: 一个圆角图片的列表,GridLayoutView

解决方案:使用BaseQuickAdapter 加载中利用 Glide加载圆角的方法加载图片
核心代码:
class ItemAdapter
(data: List<VideoBean>?) :
BaseMultiItemQuickAdapter<VideoBean, BaseViewHolder>(data) {
override fun convert(helper: BaseViewHolder, item: VideoBean) {
loadImage(
mContext,
getResUrl2(item.vod_pic!!),
helper.getView<ImageView>(R.id.video_push_img),
ConstantUtils.IMAGE_VIDEO_FACE
)
}
}
出现问题AndroidMoniter检测到存在内存抖动
解决方案:
<com.makeramen.roundedimageview.RoundedImageView
app:riv_corner_radius="9dp"
android:id="@+id/video_push_img"
android:layout_width="match_parent"
android:layout_height="161dp"
android:scaleType="fitXY"/>
内存运行平稳——抖动消失:

具体原因后续分析,但是convert会循环执行(没经过一个item,执行一次)这个是确定的,目测是glide处理的逻辑造成的。
tips: 建议以后遇到圆角图片列表的问题,采用RoundImage类似的控件做,不要作在加载里面。