【问题标题】:Child Linear Layout is not using the full parent's height子线性布局未使用父级的完整高度
【发布时间】:2014-09-25 03:16:57
【问题描述】:

我有一个带有另一个 LinearLayout 作为其子级的 LinearLayout。 子 LinearLayout 应该是父级大小的一半,但它只有父级高度的 40%。

这就是我添加子 LinearLayout 的方式:

AddView (childLinearLayout, new LayoutParams (LayoutParams.MatchParent, 0, .5f));

父LinearLayout具有垂直方向和权重总和为1。

【问题讨论】:

  • 我读过一些关于填充视口的文章,但我不确定这是否是答案或如何在代码中分配它。
  • 你在使用滚动视图吗
  • 没有。两者都是线性布局。外部线性布局包含在相对布局中,但我认为这并不重要
  • 你有没有试过设置parent的weightsum?另外,尽量不要将高度归零。有人说在这方面它不像 xml。
  • 是的,weightsum 设置为 1。如果我不将高度设置为零,则布局权重将被忽略。

标签: android android-layout view android-linearlayout


【解决方案1】:

也许这段代码可以帮助你:

       layout.addView(childLayout,new LayoutParams (LayoutParams.MatchParent, LayoutParams.MatchParent, .5f));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 2016-11-14
    • 1970-01-01
    相关资源
    最近更新 更多