Sebastian Ziegler Sebastian Ziegler - 2 months ago 6
Android Question

Layout issue depending on size

I'm having problems with a Table Layout. When a text is long in one of the buttons that the Layout has it shows the buttons wrongly. Here is what I'm talking about:

1- Here I've a table layout showed perfectly.:

enter image description here

2- Here's a grid with the problem that I can't fix:

enter image description here

The button is expanding when the text is long, I need a fixed size grid and I already tried putting on Width "match_parent" and "wrap_content". Here's the layout:

<?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"
android:background="@android:color/white" >

<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >

<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/query_bank_mercantil"
android:gravity="top"
android:textColor="@android:color/white" />

<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/sample_1"
android:gravity="top"
android:text="@string/card_extra_tip_1" />
</TableRow>

<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/sample_2"
android:gravity="top"
android:text="@string/card_extra_buy" />

<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/sample_3"
android:gravity="top"
android:text="@string/card_extra_tip_3" />
</TableRow>

<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >

<Button
android:id="@+id/button5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/sample_4"
android:gravity="top"
android:text="@string/card_extra_tip_3" />

<Button
android:id="@+id/button6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/sample_5"
android:gravity="top"
android:text="@string/card_extra_tip_4" />
</TableRow>

</TableLayout>

Answer

Set every button width to 0:

<Button android:layout_width="0dp" ... >
Comments