如何降低行高。 (表格布局>表格行)

How to decrease row height. (TableLayout>TableRow)

TableLayout 中的行高过多,高于文本所需的高度。 我玩过许多不同的价值观,但无法做到正确。 According to the docsTableLayout 的子项的默认值为 wrap_content, 但行高似乎不止于此。 它还说宽度的值总是wrap_content, 所以没有必要设置它。 通过 "children" 是否仅表示直接子级(在本例中为 TableRow), 还是全部在下面(在本例中为 TextView)?

如何减小行高?

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="*"
    android:stretchColumns="*"
    android:paddingLeft="10dp"
    android:paddingRight="10dp">

<TableRow
    android:id="@+id/tableRow1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">
    <TextView
        android:id="@+id/textViewNameLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="@string/name_string"
        android:gravity="start">
    </TextView>
    <TextView
        android:id="@+id/textViewName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="Michael Foucalt"
        android:gravity="start">
    </TextView>
    <TextView
        android:id="@+id/textViewTitleLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="@string/title_string"
        android:gravity="start"
        android:padding="10dp">
    </TextView>
    <TextView
        android:id="@+id/textViewTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="Philosopher"
        android:gravity="start">
    </TextView>
</TableRow>

<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">
    <TextView
        android:id="@+id/textViewPhoneLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="@string/phone_string"
        android:gravity="start">
    </TextView>
    <TextView
        android:id="@+id/textViewPhone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="555.111.2222"
        android:gravity="start">
    </TextView>
    <TextView
        android:id="@+id/textViewFaxLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="@string/fax_string"
        android:gravity="start"
        android:padding="10dp">
    </TextView>
    <TextView
        android:id="@+id/textViewFax"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="555.123.4567"
        android:gravity="start">
    </TextView>
</TableRow>

<TableRow
    android:id="@+id/tableRow3"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">
    <TextView
        android:id="@+id/textViewAddressLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="@string/address_string"
        android:gravity="start">
    </TextView>
    <TextView
        android:id="@+id/textViewAddress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="555 Champs Elysses"
        android:gravity="start">
    </TextView>
    <TextView
        android:id="@+id/textViewCityLabel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="@string/city_string"
        android:gravity="start"
        android:padding="10dp">
    </TextView>
    <TextView
        android:id="@+id/textViewCity"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:typeface="sans"
        android:textSize="18sp"
        android:text="Paris"
        android:gravity="start">
    </TextView>
</TableRow>
</TableLayout>

以下是显示当前显示和所需显示的图像:

请删除:

android:layout_weight="1"

来自 TableRow 元素。它将导致行沿屏幕长度均匀拉伸。

编辑 此实例中的子项都是 TableRow 和 TextView。这就是为什么做这样的事情是合法的:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

    <TextView
         android:id="@+id/textViewNameLabel"
         android:gravity="start"
         android:text="@string/name_string"
         android:textSize="18sp"
         android:textStyle="bold"
         android:typeface="sans" />

         .
         .
         .

    </TableRow>
</TableLayout>

它们都会自动分配 wrap_content 通过包装在 TableLayout

中的宽度和高度属性

编辑 2: 从所有 TextView 组件中删除:

android:padding="10dp"