簡體   English   中英

ConstraintLayout:如何以編程方式將屏幕划分為屏幕高度的兩個相等部分

[英]ConstraintLayout: how to divide screen in two equal parts of screen height programmatically

如何以編程方式將屏幕分成兩個相等的高度和約束布局?

為此,您需要將高度設置為零,然后相應地設置百分比。 例如,

    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);
    

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM