2013-02-28 40 views
0

我似乎无法弄清楚为什么我不能将datepicker和timepicker在分界线下水平放置,当我把它的layout_width设置为match_parent。相对布局中心不工作分界线视图

当我把分界线的layout_width换成wrap_content时,拾取器水平居中。但是这条线不能填补相对的观点。

我只是困惑,我不明白发生了什么事情。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center_horizontal" > 

    <!-- Dividing Line --> 
    <TextView 
     android:id="@+id/BlueLine" 
     android:layout_width="match_parent" 
     android:layout_height="2dip" 
     android:background="@color/holo_blue_light" /> 

    <DatePicker 
     android:id="@+id/DatePicker" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/BlueLine" 
     android:layout_marginRight="40dp" /> 

    <TimePicker 
     android:id="@+id/TimePicker" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/BlueLine" 
     android:layout_toRightOf="@+id/DatePicker" /> 

</RelativeLayout> 

回答

1

使用相对布局的任何特定原因?我认为使用线性布局 - 蓝线的垂直线和另一个可以包含日期选择器和时间选择器的线性布局父元素,您可以更容易地完成所需的布局。然后在其父布局元素中的日期选择器和时间选择器水平。

+0

我有使用线性布局工作,但我读了相对布局会更有效。我错了吗? – user1848850 2013-02-28 23:51:55

+0

我不认为这会产生显着的差异,根据您在布局中的元素的数量和类型。 – 2013-03-01 14:52:43

+0

好吧,我认为你是对的。谢谢 – user1848850 2013-03-01 20:55:39