我似乎无法弄清楚为什么当我把它的layout_width设置为match_parent时,我不能将datepicker和timepicker水平居中在分界线下。
当我将分界线的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>
答案 0 :(得分:1)
使用相对布局的任何具体原因?我认为使用线性布局可以更轻松地完成所需的布局 - 蓝线垂直,另一个线性布局父元素可以包含datepicker和timepicker。然后在其父布局元素中为datepicker和timepicker水平。