在使用imageview控件时,由于图片大小不一致,需要给图片设置个最大宽高。设置后的代码如下:


LinearLayout ll = new LinearLayout(ConsumeInfo.this);  
ll.setOrientation(LinearLayout.HORIZONTAL);          
//设置小图标  
ImageView imageView = new ImageView(ConsumeInfo.this);              
Bitmap bitmap = BitmapFactory.decodeFile((String)mData.get(position).get("imgpath")); 
imageView.setImageBitmap(bitmap);  
imageView.setMaxHeight(50);
imageView.setMaxWidth(50);
ll.addView(imageView);     

              运行之后,Imageview  仍然被撑开,难道是MaxWidth,MaxHeight不起作用,抓紧翻阅api文档,找到下面的解释:

                       An optional argument to supply a maximum width for this view. Only valid if setAdjustViewBounds(boolean) has been set to true. 

文档中说得很清楚,抓紧修改如下:


LinearLayout ll = new LinearLayout(ConsumeInfo.this);  
ll.setOrientation(LinearLayout.HORIZONTAL);          
//设置小图标  
ImageView imageView = new ImageView(ConsumeInfo.this);              
Bitmap bitmap = BitmapFactory.decodeFile((String)mData.get(position).get("imgpath")); 
imageView.setImageBitmap(bitmap);  
imageView.setAdjustViewBounds(true);  
imageView.setMaxHeight(50);
imageView.setMaxWidth(50);
ll.addView(imageView);     

再次运行,竟然可以了!     

更多相关文章

  1. android TextView的字体颜色设置的多种方法
  2. android 圆形头像—— android开源系列:CircleImageView自定义圆
  3. TextView关于xml属性用法(待完善)
  4. android 模拟器键盘控制键 以及 设置模拟器屏幕大小
  5. TableLayout
  6. android检查网络连接状态的变化,无网络时跳转到设置界面
  7. 转:Android(安卓)设置EditText光标颜色及粗细
  8. android shape的使用
  9. Android中的lcd_density设置

随机推荐

  1. android开发中英文切换
  2. Android(安卓)音视频开发(四) -- CameraX
  3. adb命令——初始环境安装
  4. android studio中直接运行java程序
  5. Android多Module下的Application引用方式
  6. Android(安卓)Bitmap垂直翻转
  7. android4.3 截屏功能的尝试与失败分析
  8. Android命令行编译方法,不用Eclipse IDE
  9. Android中数据存储方式一:文件形式
  10. android开发-界面设计基本知识Ⅲ