我有这个输出
http://www.cubixshade.com/images/align_row.jpg
我希望日期字段的第一个字段垂直居中对齐? 我还应该使用什么来在其他字段中从左侧或右侧添加一些空间?
最佳答案
您可以将 android:gravity="center_vertical"
属性设置为 TableRow 以使其子项垂直居中。
您还可以使用 android:layout_marginLeft
属性或 android:layout_marginRiight
属性从左侧和右侧放置一些边距,类似地,您可以使用 将边距放在顶部和底部>android:layout_marginTop
或 android: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/