【问题标题】:Vertical Layout, 2 Elements, Make the Top One Fill the Remaining Space (Bottom One Has wrap_content)垂直布局,2个元素,让上一个填满剩余空间(下一个有wrap_content)
【发布时间】:2012-10-15 21:16:20
【问题描述】:

我有以下两难境地。两个元素,一个在彼此之上。底部有wrap_content 表示高度。我希望顶部元素填充剩余空间而不使两个元素重叠(例如,如果我使用 FrameLayout 就会发生这种情况)。

所有元素的宽度为match_parent

这是一个模型(为了清楚起见,截断了一些属性):

<LinearLayout android:layout_height="match_parent">

  <CustomView android:layout_height="???????" /> 

  <TextView android:layout_height="wrap_content">

</LinearLayout>

【问题讨论】:

    标签: android android-layout height xml-layout


    【解决方案1】:
    <CustomView 
        android:layout_height="0dp"
        android:layout_weight="1"
        .../>
    

    【讨论】:

    • “FrameLayout 中的布局参数无效:layout_weight”。请注意,父 LinearLayout 没有定义 weightSum,这可能是这个原因。知道如何进行吗?
    • 不,你不需要weightSum 在那里。如果直接父级是FrameLayout,而不是如上所示的LinearLayout,这应该是一个问题。如果您需要在 FrameLayout 中使用它,请将加权视图包装在 LinearLayout 中。
    猜你喜欢
    • 2017-12-18
    • 1970-01-01
    • 2019-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    相关资源
    最近更新 更多