原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/1452
原问题描述:我想在activity中改变图片视图的宽高属性,但是我用了一个方法后没有实现,应该要怎么实现呢?
解决方案:
在这段代码中,创建了一个新的实例并且设置了尺寸:
// SET THE IMAGEVIEW DIMENSIONS
int dimens = 120;
float density = activity.getResources().getDisplayMetrics().density;
int finalDimens = (int)(dimens * density);
LinearLayout.LayoutParams imgvwDimens =
new LinearLayout.LayoutParams(finalDimens, finalDimens);
imgAlbumPhoto.setLayoutParams(imgvwDimens);
// SET SCALETYPE
imgAlbumPhoto.setScaleType(ScaleType.CENTER_CROP);
// SET THE MARGIN
int dimensMargin = 5;
float densityMargin = activity.getResources().getDisplayMetrics().density;
int finalDimensMargin = (int)(dimensMargin * densityMargin);
LinearLayout.LayoutParams imgvwMargin =
new LinearLayout.LayoutParams(finalDimens, finalDimens);
imgvwMargin.setMargins
(finalDimensMargin, finalDimensMargin, finalDimensMargin, finalDim
ensMargin);
改变已存在的ImageView尺寸,使用这个:
coupon_img.setLayoutParams(new LayoutParams(100, 100));