根据设备宽高动态设置View的大小

时间:2023-11-26 08:58:14

得到设备屏幕宽高:

WindowManager wManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display display = wManager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

设置View大小:

LayoutParams lp = mView.getLayoutParams();
lp.width = width/2;
lp.height = height/3;
mView.setLayoutParams(lp);

相关文章