2013-04-01 62 views
0

這個問題可能會提前問,但我真的不知道如何搜索它也。對齊文本同樣

我想達到的是這樣的。

city  : some city 
state : some state 
pincode : some pin code 
phone no : some phone number 

城市:是一個文本視圖和一些城市是第二個文本視圖。兩者都處於線性佈局。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
           android:orientation="horizontal" 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content"> 
       <TextView android:text="City : " 
          android:textSize="15sp" 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
       /> 
       <TextView android:text="Some city" 
          android:textSize="15sp" 
          android:id="@+id/lblPermanentCity" 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
       /> 
      </LinearLayout> 

任何幫助將感激

回答

1

我不認爲你可以只有兩個TextViews拉這一關。問題是標題(「城市」)左對齊,冒號右對齊。

如果你可以用左對齊冒號生活,你可以使用layout_weight屬性使標題欄大小相同的所有行,像這樣:

... 
<TextView android:text="City:" 
      android:layout_height="wrap_content" 
      android:layout_width="0" 
      android:layout_weight="40"/> 
<TextView android:text="some city" 
      android:layout_height="wrap_content" 
      android:layout_width="0" 
      android:layout_weight="60"/> 

這將使標題欄的40%寬度和值列的寬度的60%。確保您的LinearViewlayout_widthmatch_parent

如果你真的必須在中間的冒號,只是增加第三的TextView的結腸,給它一個固定的寬度(wrap_content相同內容的就夠了)

+0

我是否需要將width屬性更改爲所有父線性佈局的match_parent? –

+0

我不好意思我改變了高度屬性 –

+1

感謝您的正確答案:) –

1

你可以每行使用三個TextView s,一個用於城市,州等,一個用於「:」,另一個用於「某個城市」等。然後將它們放在RelativeLayout中,並將你的冒號(:)與最大的TextView的右邊緣(可能是你的「電話號碼」)。

+0

是的,我可以做到這一點。感謝您的建議:) –

+0

不客氣。 – TronicZomB

1

爲什麼你不table.I認爲這是你的問題的最佳解決方案。