问题

recyclerView中 item有ImageView,ImageView大小根据图片大小而改变大小

解决方案

GlideApp.with(mContext)                        .asBitmap()                        .load(item.getContent())                        .error(R.drawable.default_bg)                        .diskCacheStrategy(DiskCacheStrategy.ALL)                        .into(new SimpleTarget() {                            @Override                            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {                                int widht = resource.getWidth();                                int height = resource.getHeight();                                if(widht>pic_max_width){                                    float multiple = ((float) widht)/pic_max_width+0.5f;                                    widht = (int) (widht/multiple);                                    height = (int) (height/multiple);                                }                                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) img.getLayoutParams();                                params.width = widht;                                params.height = height;                                img.setLayoutParams(params);                                img.setImageBitmap(resource);                            }                        });

pic_max_width:

pic_max_width = DisplayUtils.getScreenWidth(this)-DisplayUtils.dip2px(this,50);

问题解决 50是ImageView的左右margin

更多相关文章

  1. Android(安卓)Studio Error:Connection timed out: connect.解决
  2. 解决Error:Android(安卓)Dex: com.android.dex.DexIndexOverflow
  3. 【Android笔记】Android统计文件夹大小,删除文件夹下的所有文件方
  4. Android开发常见异常和解决方案(二)
  5. 使用bitmap缩略图,解决图片大小超过预算的VM的问题
  6. android按屏幕大小动态确定控件位置及大小
  7. Android(安卓)Studio编译使用了Maven的工程卡住的解决方案
  8. Android(安卓)DownloadManager 使用
  9. Android界面加载完成后自动弹出软键盘的解决方案

随机推荐

  1. Mysql5.7.11绿色版安装教程图文详解
  2. mysql “ Every derived table must have
  3. mysql去重的两种方法详解及实例代码
  4. MySQL使用show status查看MySQL服务器状
  5. MySQL闪回(flashback)原理与实战
  6. MySQL启用慢查询日志记录方法
  7. mysql优化利器之explain使用介绍
  8. mysql explain的用法(使用explain优化查
  9. MySQL索引操作命令详解
  10. MySQL创建全文索引分享