0

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>
4

1 に答える 1

1

相対レイアウトを使用する具体的な理由はありますか?線形レイアウト(青い線の垂直線と、日付ピッカーとタイムピッカーを含むことができる別の線形レイアウトの親要素)を使用すると、目的のレイアウトをはるかに簡単に実現できると思います。次に、親レイアウト要素内のdatepickerとtimepickerを水平にします。

于 2013-02-28T21:06:05.097 に答える