Android 使日期选择器和时间选择器更小

Android 使日期选择器和时间选择器更小,android,Android,有没有办法在Android中制作更小的日期选择器和时间选择器(但所有部分都可见)?我试图设置布局宽度,但日期选择器不可见,只显示在左上角。使用“dp”代替布局宽度,使用权重百分比使其变小。 要使android:layout\u权重有效,请将android:layout\u width设置为0 android:layout\u height=“wrap\u content” android:layout_weight=“.33” android:layout\u width=“0dip” andr

有没有办法在Android中制作更小的日期选择器和时间选择器(但所有部分都可见)?我试图设置布局宽度,但日期选择器不可见,只显示在左上角。

使用“dp”代替布局宽度,使用权重百分比使其变小。 要使android:layout\u权重有效,请将android:layout\u width设置为0

android:layout\u height=“wrap\u content”

android:layout_weight=“.33”

android:layout\u width=“0dip”

android:textSize=“12sp”
使用以下属性:

示例:80%原版

android:scaleY="0.8" 
android:scaleX="0.8"

另一种解决方案:


将其放入
LinearLayout
并手动设置
LinearLayout
的高度

您可以这样简单缩放:

android:scaleY=“0.5” android:scaleX=“0.5”

要得到一半的尺寸

为了得到更小的填充空间,
android:padding=“-20dp”

从框架上看,选择器可能与其他视图重叠,但在应用程序中,不会重叠


填充效果会很好,按钮也会很好。

这对我来说非常有效,可以在小屏幕上以横向模式在对话中设置日期和时间选择器,并具有自定义布局。将容器(LinarLayout)的权重和设置为100,然后在layout_weight属性中使用小部件将其添加到100

    <LinearLayout
        android:orientation="horizontal" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:weightSum="100"
        android:layout_gravity="center_horizontal">

            <DatePicker 
                android:id="@+id/dlgDateTimePickerDate"
                android:layout_width="wrap_content"
                android:layout_weight="50"
                android:layout_height="wrap_content" />

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

(这实际上是可行的,其他人则不然)经过多次搜索后,这起到了作用:

<DatePicker
    android:id="@+id/dp_datepicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleX="0.7"
    android:scaleY="0.7"
    android:layout_marginLeft="-30dp"
    android:layout_marginRight="-30dp"
    android:datePickerMode="spinner"
    />

<TimePicker
    android:id="@+id/tp_timepicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleX="0.7"
    android:scaleY="0.7"
    android:layout_marginLeft="-30dp"
    android:layout_marginRight="-30dp"
    android:timePickerMode="spinner"
    />

android:scaleX=“0.7”
缩小了可视选择器(它适用于
DatePicker
TimePicker
),并且
android:layout\u marginLeft=“-30dp”
允许减少空间

注: 使用
android:padding=“-30dp”
的所有尝试均无效,使用
android:layout\u margin=“-30dp”
(未指定侧面)也无效。希望这能帮助那些像我一样迷路的人


顺便说一句,谷歌修复了你那该死的DatePicker API

你可以试试这个:嘿,我不确定这对你有什么帮助,但我也发现原来的计时器非常笨重,因此我自己做了一个:)查看我的计时器,了解更多信息。我制作的时间选择器大约是原来的一半大小,所以它肯定更小:)。请检查我的解决方案(并希望接受它,因为这个页面是我的google feed中的第一个结果,我花了几个小时来修复它)遵循这个答案,它工作起来很有魅力!事实上,当我给出我的答案时,它曾经起作用。现在,随着框架的发展,它没有…它仍然占据相同的空间(datepicker较小,但有很大的空间和无用的空间)我如何解决这个问题?也许你必须定制你的datepicker。例如:Allan Ramírez是对的,选取器缩小了,但仍然占据了相同的空间。android:padding=“-20dp”对时间选取器不起作用