android - 如何在 Android 中使用表格行垂直对齐 TextView 字段

标签 android row

我有这个输出

http://www.cubixshade.com/images/align_row.jpg

我希望日期字段的第一个字段垂直居中对齐? 我还应该使用什么来在其他字段中从左侧或右侧添加一些空间?

最佳答案

您可以将 android:gravity="center_vertical" 属性设置为 TableRow 以使其子项垂直居中。

您还可以使用 android:layout_marginLeft 属性或 android:layout_marginRiight 属性从左侧和右侧放置一些边距,类似地,您可以使用 将边距放在顶部和底部>android:layout_marginTopandroid:layout_marginBottom

如果你想拉伸(stretch)列那么你可以使用 android:layout_weight 属性来定义列的权重。

作为引用,您可以看到下面的 2 列示例

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout01"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1" >

    <TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical" >

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Male"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/etNoOfMale"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" 
        android:inputType="number"/>
    </TableRow>

    <TableRow
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical" >

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Female"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/etNoOfFemale"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" 
        android:inputType="number"/>
    </TableRow>

</TableLayout>

关于android - 如何在 Android 中使用表格行垂直对齐 TextView 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13356307/

相关文章:

java - 如果应用程序是从 google play 下载的,android facebook 登录将停止工作

java - ViewPager 在 Fragment 中包含 Fragment

php - 插入新行后获取 AUTO_INCRMENT 值

iPhone SDK : How to detect a row-hit while in the editing mode?

python - 行是 3 个最新值的总和

Excel 2016 : Insert Row ABOVE find result in table

android - 带有两个 EditText 字段的 AlertDIalog

android - 如何在 Android 安装时将大文件保存在外部存储设备上?

java - 包R错误

r - 如何使用 R 将每个文件的数据添加为附加行,从而将不同的 .csv 文件合并为一个完整的文件?