答案 0 :(得分:10)
您可以将android:gravity="center_vertical"
属性设置为TableRow,使其子项垂直居中。
此外,您可以使用android:layout_marginLeft
属性或android:layout_marginRiight
属性从左侧和右侧放置一些边距,类似地,您可以使用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>
答案 1 :(得分:-1)
你可以在你的xml文件页面中使用下面的标签来正确对齐,如果可以提供你所面对的pblm的详细信息,我可以给出更多解释。
android:layout_marginLeft="25dp"
android:layout_below="@+id/imageView1"
第一个代码从左边开始给出25dp的边距,第二个代码只是将字段对齐到imageview1下面。
还有另一种方法 只需右键单击文本视图或您在设计页面中添加的任何内容,选择其他属性 - >布局参数 - >然后选择您需要的项目[它包含所有对齐属性。
希望这个能帮助你。谢谢