【发布时间】:2014-04-22 15:20:46
【问题描述】:
我正在尝试用 3 个 TableRows 绘制一个 TableLayout。该表在扩展 DialogFragment 的 xml 文件(见下文)中定义。表格的所有 3 行都有
layout_height = "wrap_content"
并且每行的高度计算正确。但是,封闭的 TableLayout 包含一些较大的边距,并且它没有按应有的方式“包装”其内容。我在这里做错了什么?
<?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>
【问题讨论】:
标签: android xml android-tablelayout