Is there any way to make smaller DatePicker and TimePicker (but to be visible all parts ) in Android ? I tried to set layout_width="130dp" but then DatePicker isn't visible, just left upper corner.
-
you can try with this: http://andmobidev.blogspot.com/2010/01/setting-width-of-view-using-percentage.html – apps Nov 15 '10 at 01:59
-
Hey there - I am not sure this is gonna help you, but I also found the original TimePicker to be quite clunky, hence I made my own one :) check out my [original question](http://stackoverflow.com/questions/5921543/android-looking-for-different-timepicker-style) for more information. The TimePicker I made is about half the size of the original one - so it definitely is smaller :). – Ready4Android May 08 '11 at 16:39
-
checkout my solution (and hopefully accept it because this page was the first result in my google feed and it took me hours to fix it) – HaydenKai Jun 02 '16 at 12:52
-
Follow this answer, it work like charm! http://stackoverflow.com/a/34523787/1983018 – cuasodayleo Jun 27 '16 at 02:46
6 Answers
Use properties follow:
Example smaller 80% original
android:scaleY="0.8"
android:scaleX="0.8"

- 1,572
- 1
- 19
- 22
-
2[Note: requires API level 11 (Android 3.0)](http://developer.android.com/reference/android/view/View.html#setScaleX(float)). – Pang Apr 04 '14 at 11:34
-
17It still occupies the same space (the datepicker is smaller, but have a big margin and useless space around) How can I solve this issue? – Allan Ramírez Sep 21 '14 at 23:10
-
maybe you have to custom your datepicker. ex: https://github.com/luminousman/DatePicker – Huỳnh Ngọc Bang Apr 24 '15 at 04:26
-
Allan Ramírez is right, the picker shrunk but it still occupies the same space around. – Jose Manuel Abarca Rodríguez May 21 '15 at 23:31
(This actually works and others don't) After much searching this worked:
<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"
/>
The android:scaleX="0.7"
is what shrinked the visible picker (it works for DatePicker
and TimePicker
) and the android:layout_marginLeft="-30dp"
allowed for the space to be reduced.
Note:
All attempts at using android:padding="-30dp"
did not work and using android:layout_margin="-30dp"
(without a side specified) also did not work. Hopefully this helps those who were as lost as me
P.S. Google get your freaking DatePicker API fixed!

- 871
- 7
- 31
This worked for me to fit a date and time picker in a dialogue with a custom layout in landscape mode on a small screen. Set the weightsum of a container (LinarLayout) to 100 and then fill it with widgets adding up to 100 in layout_weight property.
<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>

- 477
- 6
- 11
Instead of using "dp" for the layout width , use percentages in weight to make it smaller. For android:layout_weight to be effective, put android:layout_width to 0 dip.
android:layout_height="wrap_content"
android:layout_weight=".33"
android:layout_width="0dip"
android:textSize="12sp"

- 4,187
- 4
- 34
- 44
-
2Actually when I gave my answer, it used to work. Now as the framework evolved, it doesn't. – Muhammad Shahab Jan 17 '13 at 21:11
You can simple scale like this:
android:scaleY="0.5"
android:scaleX="0.5"
to get the half of the size.
And to get a smaller padding, android:padding="-20dp"
Looking from the framework the picker may overlap other views, but in the app, it will not.
The padding is going to work perfectly and the buttons also.

- 3,670
- 1
- 30
- 33
Another solution:
Put it in a LinearLayout
and set the height of the LinearLayout
manually

- 22,810
- 38
- 143
- 225