如何让View填充剩余的空间?

时间:2013-09-13 08:31:53

标签: android android-layout android-view

我有一个视图的布局,A和B,

___
|A|
|B|
---

A的高度可以变化很大。我希望B有ParentHeight-A.height,并希望通过xml(我知道我可以通过编程调整它们,但希望避免它)。

如何使用Android布局系统实现这一目标?

2 个答案:

答案 0 :(得分:2)

这绝对是基本的布局。我建议你阅读LinearLayout和宽度/高度规格。一般来说,您的布局将是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View android:id="@+id/A
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <View android:id="@+id/B
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

答案 1 :(得分:2)

使用LinearLayout并将B的layout_weight属性设置为1.它将占用A占用所需空间后留下的所有空间。

相关问题