Android(安卓)ImageView控件的MaxWidth、MaxHeight不起作用
在使用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 ifsetAdjustViewBounds(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);
更多相关文章
- ImageButton与Button
- Android(安卓)EditText文本输入框禁止输入空格
- Android:UI控件风格与主题、selector、Theme
- Android(安卓)中文 API 文档 (44) —— Chronometer.OnChronometer
- android 获取坐标[整理]
- 【Android】重写原生控件及使用
- Android官方文档翻译 十 2.3Styling the Action Bar
- Android(安卓)点击事件冲突之拦截父控件事件 交给子控件处理
- Android自定义进度条-带文本(文字进度)的水平进度条(ProgressBar