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 所在上级布局

posted on 2016-05-03 08:38  lvlv岁月流逝  阅读(427)  评论(0编辑  收藏  举报

导航