I have a problem with setting the widths of columns in a TableLayout
. This issue has been discussed previously:
How to set Table width and number of Columns in TableLayout in Android
How to get a TableLayout with 2 columns of equal width
Set equal width of columns in table layout in Android
but I'm not finding a solution. The code below does indeed set the columns to equal width, but it seems to key off the button in the 1st column. Since the text of the button in the
2nd column is wider, it displays in an untoward manner.
Desired display:
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/menu1Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
android:background="@color/darkgrey2"
android:contentDescription="@string/menu1"
android:onClick="click1"
android:padding="60dp"
android:text="hello"
android:textColor="@color/white"
android:textSize="32sp"
android:textStyle="bold" />
<Button
android:id="@+id/menu2Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
android:background="@color/darkgrey2"
android:contentDescription="@string/menu1"
android:onClick="click1"
android:padding="60dp"
android:text="hellothere"
android:textColor="@color/white"
android:textSize="32sp"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/menu3Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
android:background="@color/darkgrey2"
android:contentDescription="@string/menu1"
android:onClick="click1"
android:padding="60dp"
android:text="hello"
android:textColor="@color/white"
android:textSize="32sp"
android:textStyle="bold" />
<Button
android:id="@+id/menu4Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="1"
android:background="@color/darkgrey2"
android:contentDescription="@string/menu1"
android:onClick="click1"
android:padding="60dp"
android:text="hello"
android:textColor="@color/white"
android:textSize="32sp"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
Edit:
Removing margin and padding results in:
Edit2:
Removing only margin: