【问题标题】:Android LinearLayout fill-the-middleAndroid LinearLayout 填充中间
【发布时间】:2010-11-15 23:46:09
【问题描述】:

我有一个带有 3 个嵌套 LL 的垂直设置高度 (300px) 线性布局 (LL)。 1 和 3 使用 android:layout_height="wrap_content" 设置,中间使用 android:layout_height="fill_parent" 设置。令我沮丧的是,第三个 LL 被推出,第二个填充父布局到底部。我如何达到预期的效果,因为我想通过中间部分扩展和收缩来调整外部容器的大小以适应变化

【问题讨论】:

    标签: android android-linearlayout


    【解决方案1】:

    原来(感谢 Mark Murphy for the answer)我所寻找的只是将中间行设置为

    layout_height="0px" 和 layout_weight="1"

    如果,在所有 wrap_content 和固定大小的项目都分配给 沿轴(水平或垂直),该轴上仍有空间 剩下的,LinearLayout 然后将剩余空间分配给那些 具有指定权重的小部件,与权重成比例。

    【讨论】:

    • layout_weight only for the 2nd LL 是这里的关键。
    • 感谢您的回答。不知道为什么 layout_height="wrap_content" 和 layout_weight="1" 也适用于我测试过的少数 Android 设备。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    相关资源
    最近更新 更多