在 LinearLayout 中对齐两个选择器

Align two pickers in a LinearLayout

我正在用选择器元素做片段。我在 LinearLayout 中有两个选取器(NumberPicker 和 TimePicker),我想对齐它们。

这是我的 xml 代码:

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

  <LinearLayout 
  android:layout_width="match_parent"
  android:layout_height="wrap_content" 
  android:layout_weight="1"
  android:orientation="vertical">

    <Switch
    android:id="@+id/buscar_instalaciones_horario_fragment_switch1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1" />

    <TextView                
    android:id="@+id/buscar_instalaciones_horario_fragment_tv_subtitulo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="30dp"
    android:text="@string/del_14_de_junio_al_31_de_agosto"
    android:textAppearance="?android:attr/textAppearanceSmall" />

 </LinearLayout>

 <LinearLayout 
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_weight="1"
 android:gravity="center_horizontal">

   <RadioGroup 
    android:id="@+id/buscar_instalaciones_horario_fragment_radiogroup"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

       <RadioButton 
            android:id="@+id/buscar_instalaciones_horario_fragment_radiobutton_abierto"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Apertura"
            android:checked="true"
            android:layout_weight="1"/>

        <RadioButton 
            android:id="@+id/buscar_instalaciones_horario_fragment_radiobutton_cerrado"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cierre"
            android:layout_weight="1"/>           
   </RadioGroup>


</LinearLayout>

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:orientation="horizontal">

        <NumberPicker
                    android:id="@+id/buscar_instalaciones_horario_fragment_diasdelasemanaPicker"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:layout_weight="1" />

        <TimePicker android:id="@+id/buscar_instalaciones_horario_fragment_timePicker" 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"/>
</LinearLayout>


</LinearLayout>

现在是屏幕:

如您所见,两个拾取器没有对齐。

修改这段代码

<LinearLayout 
android:layout_width="match_parent"
android:layout_height="wrap_content" 
android:layout_weight="2"
android:orientation="horizontal">

    <NumberPicker
                android:id="@+id/buscar_instalaciones_horario_fragment_diasdelasemanaPicker"
                android:layout_width="0dp"
                android:layout_height="wrap_content" 
                android:layout_weight="1" />

    <TimePicker android:id="@+id/buscar_instalaciones_horario_fragment_timePicker" 
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>
</LinearLayout>

已编辑:

通过在 LinearLayout

中添加这一行解决了
android:gravity="center_vertical"