【问题标题】:ConstraintLayout: how to divide screen in two equal parts of screen height programmaticallyConstraintLayout:如何以编程方式将屏幕划分为屏幕高度的两个相等部分
【发布时间】:2021-05-05 21:55:39
【问题描述】:

如何以编程方式使用约束布局将屏幕分成两个相等的高度?

【问题讨论】:

    标签: android xml android-layout android-linearlayout android-constraintlayout


    【解决方案1】:

    为此,您需要将高度设置为零,然后相应地设置百分比。例如,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-12
      • 2019-10-17
      • 2019-07-22
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多