George
George

Reputation: 3807

How to let a View fill the remaining space?

I have a layout with tho views, A and B,

___
|A|
|B|
---

A can have very varying height. I want B to have ParentHeight-A.height, and would like to this via xml (I know I can resize them programmatically, but hope to avoid it).

How can I achieve this with the Android layout system?

Upvotes: 3

Views: 735

Answers (2)

Anup Cowkur
Anup Cowkur

Reputation: 20553

Use a LinearLayout and set B's layout_weight property to 1. It will occupy all the space that is left after A occupies the space it needs.

Upvotes: 3

Aleks G
Aleks G

Reputation: 57306

This is absolutely basic layout stuff. I suggest you read up about LinearLayout and width/height specifications. Generally speaking, your layout will be something like this:

<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>

Upvotes: 2

Related Questions