我有这个输出
我想要第一个日期字段垂直居中对齐? 并且我应该使用什么来在其他字段中添加左右间距? http://www.cubixshade.com/images/align_row.jpg
我想要第一个日期字段垂直居中对齐? 并且我应该使用什么来在其他字段中添加左右间距? http://www.cubixshade.com/images/align_row.jpg
你可以在TableRow上设置android:gravity="center_vertical"
属性,使其子项垂直居中对齐。
此外,您还可以使用android:layout_marginLeft
属性或android:layout_marginRight
属性从左右两侧添加一些边距;同样地,您可以使用android:layout_marginTop
或android:layout_marginBottom
将边距添加到顶部和底部。
如果您想要拉伸列,则可以使用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>
您可以在XML文件页面中使用以下标签来对齐内容,如果您能提供您所面临的问题的详细信息,我可以给出更多的解释。
android:layout_marginLeft="25dp"
android:layout_below="@+id/imageView1"
第一段代码从左侧给出了25dp的边距,第二段代码只是将字段对齐到imageview1下方的右侧。
还有另一种方法 只需右键单击文本视图或您在设计页面中添加的任何内容,然后选择其他属性->布局参数->然后选择您需要的项目[它包含所有对齐属性]。
希望这可以帮助您。谢谢