CovertDad
CovertDad

Reputation: 57

How to Expand the Middle TableRow of a TableLayout in Android?

I have the following layout in my Android app:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/widget41"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<tablerow>
    <Button android:id="@+id/button_when" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:padding="10px"
        android:text="When">
    </Button>
</tablerow>
<tablerow>
    <EditText android:id="@+id/text_description" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:padding="10px"
        android:text="What happened?" android:textSize="18sp">
    </EditText>
</tablerow>
<tablerow>
    <Button android:id="@+id/button_location" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:padding="10px"
        android:text="Location">
    </Button>
</tablerow>

How can I make my layout so that the in the middle, the one with the EditText, expands to fill the entire space of the screen not taken up by the first and third items?

Upvotes: 2

Views: 2243

Answers (2)

Martin
Martin

Reputation: 11875

This can be done much simpler then the suggestion from Varundroid. android.widget.TableRow is a subclass from android.widget.LinearLayout and therefore take all parameter a layout can take. So this will do the trick:

  <TableRow
    android:layout_height='fill_parent'
    android:layout_weight='1.0'
    android:layout_width='fill_parent'
  >
  …
  </TableRow>

Note that setting android:layout_weight is usually needed when expanding is desired.

Upvotes: 1

Varundroid
Varundroid

Reputation: 9234

It is very simple.

There are two ways

  1. find out the screen density and resolution and then find out how much space is required by first and last.
  2. Now simply allot the rest of the space to your middle row by using android:layout_height="space which has been left"

Another way is to change android:layout_height until its cover the whole screen

My personal opinion is to go with 1st one because screen sizes can be varied device to device so you should play safe.

By the way are you sure your code is working? because your t is in small letter in your tag <tablerow> wheres it should be <TableRow>. and sometine if you won't pass android:layout_height and android:layout_width in every tag then it could cause an error in your layout.

Play safe else your app will be turned out to be buggy.

I hope it will help.

Upvotes: 0

Related Questions