Tai Dao
Tai Dao

Reputation: 3437

Remove space of TableLayout column

I'm align 9 checkbox by TableLayout. I've align column by android:stretchColumns but the space between column are high. How to fix that space.

<TableLayout
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:stretchColumns="1" >

                        <TableRow
                            android:id="@+id/tableRow1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >

                            <CheckBox
                                android:id="@+id/cbRestaurant"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="@string/drawer_select_restaurant"
                                android:textSize="14sp" />

                            <CheckBox
                                android:id="@+id/cbHotel"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="@string/drawer_select_hotel"
                                android:textSize="14sp" />

                            <CheckBox
                                android:id="@+id/cbNightLife"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="@string/drawer_select_nightlife"
                                android:textSize="14sp" />
                        </TableRow>

                        <TableRow
                            android:id="@+id/tableRow2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >

                            <CheckBox
                                android:id="@+id/cbShopping"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="@string/drawer_select_shopping"
                                android:textSize="14sp" />

                            <CheckBox
                                android:id="@+id/cbEmbrassies"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="@string/drawer_select_embrassies"
                                android:textSize="14sp" />

                            <CheckBox
                                android:id="@+id/checkBox3"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="@string/drawer_select_attaction"
                                android:textSize="14sp" />
                        </TableRow>

                        <TableRow
                            android:id="@+id/tableRow3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" >

                            <CheckBox
                                android:id="@+id/cbShopping1"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="@string/drawer_select_hospital"
                                android:textSize="14sp" />

                            <CheckBox
                                android:id="@+id/cbEmbrassies1"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="@string/drawer_select_bank"
                                android:textSize="14sp" />

                            <CheckBox
                                android:id="@+id/checkBox4"
                                android:layout_width="0dp"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="@string/drawer_select_police"
                                android:textSize="14sp" />
                        </TableRow>
                    </TableLayout>

My current table
enter image description here

The result I want
enter image description here

Upvotes: 1

Views: 1556

Answers (1)

Jschools
Jschools

Reputation: 2768

Remove the android:layout_weight="1" from each CheckBox and set android:layout_width="wrap_content". That's confusing the TableRow. Then, set android:stretchColumns="*" instead of just 1. This will distribute the available width to all columns.

Upvotes: 1

Related Questions