//获取屏幕宽高
DisplayMetrics display = this.getResources().getDisplayMetrics();
int width = display.widthPixels;
int height = display.heightPixels;
//获取Toolbar宽高
int w = View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED);
int h = View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED);
mToolbar.measure(w, h);
int toolbarh = mToolbar.getMeasuredHeight();
int toolbarw = mToolbar.getMeasuredWidth();
//获取ll宽高
ll.measure(w, h);
int llh = ll.getMeasuredHeight();
int llw = ll.getMeasuredWidth();
//设置rl高度
ViewGroup.LayoutParams pp = rl.getLayoutParams();
pp.height = height - toolbarh - llh;
rl.setLayoutParams(pp);
Android开发之控件宽高获取与设置
最新推荐文章于 2026-05-02 07:45:03 发布
本文介绍了一种通过测量屏幕尺寸及组件大小来实现视图自适应调整的方法,包括获取屏幕宽高、Toolbar及自定义布局的高度,并据此动态设置内容区域的高度。

4065

被折叠的 条评论
为什么被折叠?



