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 所在上级布局
时间: 2024-10-07 21:01:10