代码之家  ›  专栏  ›  技术社区  ›  motis10 towith

Android TimePicker-小时线未对齐中心

  •  2
  • motis10 towith  · 技术社区  · 9 年前

    我在自定义对话框中使用了Android TimePicker。
    小时线未对齐中心。
    正如您所看到的,对于中心控制器来说,xml看起来不错。
    是否可以从自定义对话框而不是从FragmentDialog更改时间选择器属性?我应该如何将其居中?

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:minHeight="50dp"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/titleDateAndTime"
                android:layout_width="wrap_content"
                android:layout_height="25dp"
                android:layout_gravity="center"
                android:gravity="center"
                android:text="Today"/>
    
            <ImageView
                android:id="@+id/changeDateAndTimeState"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="10dp"
                android:src="@drawable/arrow"/>
    
        </LinearLayout>
    
    <TimePicker
        android:id="@+id/time_picker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>
    
    <Button
        android:id="@+id/date_time_set"
        style="@style/Button.Buttons"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/ripple_or_holo"
        android:text="@string/call_reminder_set_button"/>
    

    Custom dialog screenshot

    2 回复  |  直到 9 年前
        1
  •  0
  •   motis10 towith    8 年前

    将每个元素居中的选项 TimePicker 不支持。
    我最后的办法是用我的布局为时间选择器创建自定义视图。

        2
  •  0
  •   Vadim Kotov First Zero    7 年前

    https://developer.android.com/reference/android/widget/TimePicker.html : 如果您查看此处,您将找不到此类方法或参数。

    此外,如果你发现一个错误来设置这个值,根据我的经验,我并不建议你使用一些异常的默认行为。因为TimePicker有很多不同的实现。 使用默认行为或不执行任何操作。

    我唯一的解决方案是:使用数字选择器等编写自己的时间选择器。