Jackie
Jackie

Reputation: 23577

How to have single view fill entire TableRow when other row has multiple rows using TableLayout

I have a layout like this....

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="fill_parent" >

  <TableRow>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Number of payrates (overtime etc)"
        android:textSize="12sp" />

    <Spinner
        android:id="@+id/num_rate"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:textSize="12sp" />
  </TableRow>

  <TableRow>

    <Button
        android:id="@+id/cont"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Continue" 
        android:layout_gravity="bottom|right"/>
  </TableRow>

</TableLayout>

Problem is that is still looks like this...

Yo Yo Yo

Meaning the button is conforming to the same amount of rows as above. Is there anyway (without switching layout types) to make it fill the entire row?

Also bonus points if you can point me towards how to move the button to the bottom of the screen.

Upvotes: 0

Views: 113

Answers (2)

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

// try this
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Number of payrates (overtime etc)"
            android:textSize="12sp" />

        <Spinner
            android:id="@+id/num_rate"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:textSize="12sp" />
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="bottom">

        <Button
            android:id="@+id/cont"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:text="Continue"/>
    </TableRow>

</TableLayout>

Upvotes: 1

Manishika
Manishika

Reputation: 5574

For row to fill entire row and to align your button to the bottom use Linear Layout instead of TableRow and give layout_gravity = "bottom".

Try the following data

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

  <TableRow
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1.0"
      >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Number of payrates (overtime etc)"
        android:textSize="12sp" />

    <Spinner
        android:id="@+id/num_rate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1.0"
        android:textSize="12sp" />
  </TableRow>

  <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom" >

      <Button
          android:id="@+id/cont"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:gravity="center_horizontal"
          android:text="Continue" />
  </LinearLayout>

</TableLayout>

Hope this works

Upvotes: 1

Related Questions