2013-04-07 39 views
0

我在同一行上有两个TextView,我希望它们每个都有一半的父宽度。而且,我想将它们放在父布局的垂直中间。TextView中心的垂直和宽度百分比

我不能使用RelativeLayout,因为我需要指定重量,我不能使用LinearLayout,因为我需要指定中心垂直属性。

那么应该使用什么布局?

预先感谢您。

回答

2
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_vertical" 
    android:orientation="horizontal" > 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="text 1" /> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="text 2" /> 
</LinearLayout> 
0

可以使用的LinearLayout,仍然垂直居中:

LinearLayout.... 
    android:layout_gravity="center_vertical" 
+1

@ minipif的答案是正确的,它会给你你所需的输出。我只是没有时间把它写出来。 – drewmoore 2013-04-07 12:58:14