Aijaz
Aijaz

Reputation: 730

How do I add 4 buttons in tablerow?

I want to make a calculator, and using a tablerow, isn't allowing me to add 4 buttons, I cannot allign them as my wish. How do I place them close to each other? Because when I add the buttons, only two and a half of them are visible, and the rest are gone. Here's the code for it.

<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/textView1"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="60dp"
     >

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="left"
        android:gravity="fill_horizontal|left" >

        <Button
            android:id="@+id/button1"
            android:layout_width="50dp"
            android:layout_height="40dp"
            android:layout_marginLeft="39dp"
            android:layout_weight="1"
            android:background="@drawable/crea"
            android:text="9"
            android:textColor="#E6005C"
            android:orientation="horizontal"
            android:textSize="30sp"
            android:textStyle="italic"
            android:typeface="normal" />

        <Button
            android:id="@+id/button3"
            android:layout_width="50dp"
            android:layout_height="40dp"
            android:layout_marginLeft="39dp"
            android:background="@drawable/crea"
            android:text="8"
            android:textColor="#E6005C"
            android:textSize="30sp"
            android:textStyle="italic"
            android:typeface="normal" />

        <Button
            android:id="@+id/button2"
            android:layout_width="50dp"
            android:layout_height="40dp"
            android:layout_marginLeft="39dp"
            android:background="@drawable/crea"
            android:text="7"
            android:textColor="#E6005C"
            android:textSize="30sp"
            android:textStyle="italic"
            android:typeface="normal" />

        <Button
            android:id="@+id/button4"
            android:layout_width="50dp"
            android:layout_height="40dp"
            android:layout_marginLeft="39dp"
            android:background="@drawable/crea"
            android:text="6"
            android:textColor="#E6005C"
            android:textSize="30sp"
            android:textStyle="italic"
            android:typeface="normal" />

    </TableRow>

This is the screenshot of how it comes up

https://i.sstatic.net/VTP2H.jpg

Upvotes: 0

Views: 178

Answers (1)

nida
nida

Reputation: 656

please try to edit your first Button might be its creating problem: write this

 <Button
            android:id="@+id/button1"
            android:layout_width="50dp"
            android:layout_height="40dp"
            android:layout_marginLeft="39dp"
            android:layout_weight="1"
            android:background="@drawable/crea"
            android:text="9"
            android:textColor="#E6005C"
            android:textSize="30sp"
            android:textStyle="italic"
            android:typeface="normal" /> 

try to Remove this LOC :

`android:orientation="horizontal"`

Upvotes: 1

Related Questions