【发布时间】:2021-05-05 21:55:39
【问题描述】:
如何以编程方式使用约束布局将屏幕分成两个相等的高度?
【问题讨论】:
标签: android xml android-layout android-linearlayout android-constraintlayout
如何以编程方式使用约束布局将屏幕分成两个相等的高度?
【问题讨论】:
标签: android xml android-layout android-linearlayout android-constraintlayout
为此,您需要将高度设置为零,然后相应地设置百分比。例如,
ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) viewTop.getLayoutParams();
lp.height = 0;
lp.matchConstraintPercentHeight = (float) 0.5;
ConstraintLayout.LayoutParams lp2 = (ConstraintLayout.LayoutParams)viewBottom.getLayoutParams();
lp2.height = 0;
lp2.matchConstraintPercentHeight = (float) 0.5;
viewTop.setLayoutParams(lp);
viewBottom.setLayoutParams(lp2);
【讨论】: