[英]How to vertically align a textview field using table row in Android
我有這個輸出
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
將邊距放到頂部和底部。
如果要拉伸列,則可以使用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文件頁面中使用下面的標簽來正確對齊,如果可以提供有關您所面臨的pblm的詳細信息,我可以給出更多解釋。
android:layout_marginLeft="25dp"
android:layout_below="@+id/imageView1"
第一個代碼給出了左邊25dp的邊距,第二個代碼只是將字段對齊到imageview1下面。
還有另一種方法只需右鍵單擊文本視圖或您在設計頁面中添加的任何內容,選擇其他屬性 - >布局參數 - >然后選擇您需要的項目[它包含所有對齊屬性。
希望這個能幫助你。 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.