android 动态设置控件宽高

android动态设置控件宽高,找了很多都不靠谱,这个是亲身尝试,可以正常设置

android 动态设置控件宽高_第1张图片

WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);ImageView image = (ImageView) findViewById(R.id.img);

image.setVisibility(View.VISIBLE);

int width = wm.getDefaultDisplay().getWidth();

LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) image

.getLayoutParams();

params.width = width;

image.setLayoutParams(params);

你可能感兴趣的:(android 动态设置控件宽高)