Imageview按比例适应屏幕大小-创新互联
DisplayMetrics dm = new DisplayMetrics();
//取得窗口属性
getWindowManager().getDefaultDisplay().getMetrics(dm);
//窗口的宽度
int screenWidth = dm.widthPixels;
ImageView mImageView = (ImageView)findViewById(R.id.login_icon); ViewGroup.LayoutParams lp = mImageView.getLayoutParams();
lp.width= screenWidth;
lp.height= RelativeLayout.LayoutParams.WRAP_CONTENT;
mImageView.setLayoutParams(lp);
mImageView.setMaxWidth(screenWidth);
mImageView.setMaxHeight(screenWidth* 5);
需要注意:
必须设置ImageView 的属性。 android:adjustViewBounds="true"
RelativeLayout 布局是指mImageView 所在上级布局
文章题目:Imageview按比例适应屏幕大小-创新互联
网站地址:http://pwwzsj.com/article/jpcej.html