I'm trying to draw a TableLayout with 3 TableRows. The table is defined in an xml file (see below) that inflates a DialogFragment. All 3 rows of the table have
layout_height = "wrap_content"
and the height of each row is computed correctly. However, the enclosing TableLayout contains some big margin and it's not "wrapping" its content as it should. What am I doing wrong here?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/borderless_blue_5dp" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="@string/CHANGE_ROOM"
android:textSize="20sp" />
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/web_safe_silver" />
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border"
android:padding="5dp" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="@string/CLIENT"
android:textSize="@dimen/text_size_regular" />
<TextView
android:id="@+id/tv_client_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:background="@drawable/dark_rect_smooth"
android:textColor="@color/discoveroom_gray"
android:textSize="@dimen/text_size_regular" />
</TableRow>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/web_safe_silver" />
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border"
android:weightSum="10"
android:padding="5dp" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="@string/ROOM"
android:textSize="16sp" />
<TextView
android:id="@+id/room_number"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="@drawable/dark_rect_smooth"
android:textColor="@color/discoveroom_gray"
android:textSize="@dimen/text_size_regular" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="@string/CHARGE"
android:textSize="@dimen/text_size_regular" />
<TextView
android:id="@+id/charge"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="@drawable/dark_rect_smooth"
android:textColor="@color/discoveroom_gray"
android:textSize="@dimen/text_size_regular"/>
</TableRow>
</TableLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/web_safe_silver" />
<ListView
android:id="@+id/alternative_rooms_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:choiceMode="singleChoice"
android:visibility="invisible" >
</ListView>
<LinearLayout
android:id="@+id/edit_buttons"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="invisible" >
<Button
android:id="@+id/btn_close"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/CANCEL"
android:textColor="#894556"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="@+id/btn_ok"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/OK"
android:textColor="#489456"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
It worked when I replaced the outer most LinearLayout with a RelativeLayout. So, I know how to fix it, but I still don't get why that happened. Additional comments are welcome.