android - 在 LinearLayout 中对齐两个选择器

标签 android android-layout android-linearlayout

我正在用选择器元素做 fragment 。我在 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>

现在是屏幕:

enter image description here

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

最佳答案

修改这段代码

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

关于android - 在 LinearLayout 中对齐两个选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29904388/

相关文章:

java - 如何使这个 libGDX 阶段/按钮接收触摸?

android - 为 PlayBook 自定义布局文件夹构建 Android 应用程序?

android - 使用 weightSum 和 layout_weight 时如何在 LinearLayout 元素上设置最小宽度

android - linearLayout 中的 float 操作按钮

java - 使用加速度计进行运动跟踪的算法建议

java - 最好使用什么布局?

java - 无法正确对齐 UI 项目

android - 从 cordova 插件访问自定义布局资源

java - Android wifi 点对点

使用 SOAP API 的 android magento 客户登录(身份验证)