Caffe Latte
Caffe Latte

Reputation: 1743

Button fill the whole row in TableLayout?

I have a LinearLayout in vertical orientation, in the first row I added one button which fills the parent.

I want to implement the same thing using TableLayout.
What I've tried so far is:

enter image description here

<TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout">
<TableRow 
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:id="@+id/firstRow">

<Button
     android:id="@+id/button1"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="Button" />
</TableRow >
</TableLayout>

The TableRow fills the parent, but the button inside the row won't fill the whole row.

How to make the button fill the parent like this?


Edit:

And how to make it vertically fill the parent like this:

enter image description here

Upvotes: 3

Views: 3749

Answers (2)

Arun M
Arun M

Reputation: 11

<TableLayout
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill"
        android:layout_weight="1">

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button" />
    </TableRow>

Upvotes: 1

Matej Špil&#225;r
Matej Špil&#225;r

Reputation: 2687

use android:layout_weight="1"

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

        <Button
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Why is doing layouts on Android" />
    </TableRow>

    <TableRow>

        <Button
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="damn" />
    </TableRow>

</TableLayout>

looks like :

enter image description here

Upvotes: 7

Related Questions