How can I reduce the size (height and width) of a DatePicker? Is there any built-in method available for this?
-
Follow this answer, It will work.http://stackoverflow.com/a/34523787/1983018 – cuasodayleo Jun 27 '16 at 08:43
5 Answers
Example of a DatePicker that is half it's original size.
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:scaleX=".5"
android:scaleY=".5" />

- 1,308
- 3
- 17
- 28
-
8this shrinks the picker within its rectangle, but does not resize the view's rectangle. that markup shows a half-size picker, but it appears in a rectangle computed at full size. this means you cannot place elements "next" to it without overriding padding and margins of those elements. – escape-llc Dec 01 '14 at 12:05
-
`error: No resource identifier found for attribute 'scaleX' in package 'android'` – Michael Feb 01 '15 at 20:00
to reduce the space occupied by the datepicker, I used both options:
android:datePickerMode="spinner"
android:calendarViewShown="false"
will look like this, which is pretty much standard and also used by a number of other apps, and does not take too much space

- 144
- 2
- 13
-
unless you're making a fancy calendar app or something, this is enough for selecting a date. thanks op – TootsieRockNRoll Mar 06 '20 at 16:28
No. You cannot reduce the size of a view beyond their minimum size. Using wrap_content ensures that the DatePicker is just big enough to enclose its contents.
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

- 6,427
- 9
- 40
- 52
-
please suggest me there is no way for doing it or by using custom layout . – Sushant Bhatnagar Jan 30 '12 at 05:27
N, we can't reduce the size of the date picker in Android, but for setting a date in our program we can use the Date Picker Dialog box. Here is the link related to that: http://developer.android.com/guide/topics/ui/controls/pickers.html

- 1,259
- 3
- 11
- 20
I think we can not reduce the actual size of the date picker view but we can use scaling and negative padding properties to make the date picker look smaller.
Scaling down the date picker by using android:scaleY and android:scaleX attributes will make the picker to look smaller but still take the same amount of view space inside the activity/ fragment. To remove the extra space around the scaled down version of date picker we can use negative padding.
For example, if we want to place two scaled down version of date pickers side by side without leaving much gap between them, then we can do so by adjusting the padding as shown below:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:padding="-40dp"
android:scaleY="0.80"
android:scaleX="0.80"/>
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:padding="-40dp"
android:scaleY="0.80"
android:scaleX="0.80"/>
</LinearLayout>
Above example shows placing the 2 date pickers side by side but we can place any other view beside a date picker by adjusting the padding as shown above.

- 251
- 1
- 4