【问题标题】:Adding "below" to Linear Layout LayoutParams将“下面”添加到线性布局 LayoutParams
【发布时间】:2023-03-08 02:14:02
【问题描述】:

我的主要(层次最高)布局是RelativeLayout。在其中,我以编程方式创建一个LinearLayout。它必须具有“低于”button1 的属性。我知道如何使用addRule() 将其添加到RelativeLayout.LayoutParams,但LinearLayout.LayoutParams 没有该选项。

【问题讨论】:

标签: java android xml android-linearlayout layoutparams


【解决方案1】:

LinearLayout 不能有以下属性。最多可以提供垂直或水平方向类型。 例如

LinearLayout layout = /* ... */;
layout.setOrientation(LinearLayout.VERTICAL);
//OR
layout.setOrientation(LinearLayout.HORIZONTAL);

【讨论】:

    【解决方案2】:

    您的LinearLayout 是其RelativeLayout 父级的子级。 LayoutParams 在其父级中指定子级的布局,因此在这种情况下,用于RelativeLayout 父级的正确LayoutParamsRelativeLayout.LayoutParams

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多