在ImageView中有一个adjustViewBounds的属性,它是做什么用的,官方给出的解释的是是否保持原图的长宽比,单独设置不起作用,需要配合maxWidth或maxHeight一起使用。我们也知道,一般在XML文件中,我们很难设置maxWidth和maxHeight.所以一般会在后台用代码来实现.
WindowManager wm = this.getWindowManager();
int screenWidth = wm.getDefaultDisplay().getWidth();
ViewGroup.LayoutParams lp1 = no_record_bzt.getLayoutParams();
lp1.width = screenWidth;
lp1.height = FrameLayout.LayoutParams.WRAP_CONTENT;
no_record_bzt.setLayoutParams(lp1);
no_record_bzt.setMaxWidth(screenWidth);
no_record_bzt.setMaxHeight(screenWidth*2 );