2013-04-01 57 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认为这是你的问题的最佳解决方案。