Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize date picker's width and height in android

Tags:

android

Can anybody tell me how to customize the date picker's width and height in android?

like image 278
mohan Avatar asked Jul 13 '11 05:07

mohan


People also ask

How can I change DatePicker size in android?

For example, android:layout_width="15dp" will set the width at a scalable value of 15. You can change 15 to whatever you want. If you want to set a specific pixel size, you can use, for example, 15px .

How do I make my DatePicker smaller?

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.

What is date and time picker in android?

Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Each picker provides controls for selecting each part of the time (hour, minute, AM/PM) or date (month, day, year).


3 Answers

The only way I've found to resize it is to simply re-scale the view. For example, if you only want 80% of the normal size, I would add these attributes:

android:scaleX="0.8"
android:scaleY="0.8"
like image 135
Don Avatar answered Sep 27 '22 17:09

Don


For DatePicker and TimePicker:

  1. android:scaleX="0.60" and android:scaleY="0.60"
    Above code will set the visible part of the Date and Time Picker to something like 60% of the total space and

  2. android:layout_marginLeft="-50dp", android:layout_marginTop="-30dp", android:layout_marginRight="-50dp", android:layout_marginBottom="-30dp"
    Above code will remove extra spaces around this picker

    padding="-40dp" doesn't worked for me so I have used margin.

    <DatePicker
          android:id="@+id/date_picker"
          android:calendarViewShown="false"
          android:layout_height="105dp"
          android:layout_width="wrap_content"
          android:scaleX="0.60"
          android:scaleY="0.60"
          android:layout_marginLeft="-50dp"
          android:layout_marginTop="-30dp"
          android:layout_marginRight="-50dp"
          android:layout_marginBottom="-30dp" />
    
    <TimePicker
          android:id="@+id/time_picker"
          android:layout_width="wrap_content"
          android:layout_height="105dp"
          android:scaleX="0.60"
          android:scaleY="0.60"
          android:layout_marginLeft="-55dp"
          android:layout_marginTop="-30dp"
          android:layout_marginRight="-50dp"
          android:layout_marginBottom="-30dp" />
    

like image 20
Pratik Saluja Avatar answered Sep 27 '22 17:09

Pratik Saluja


In your layout's XML file, change the android:layout_height and android:layout_width attributes. I am assuming you are currently using either fill_parent or wrap_content for the values of these attributes, however you can be more specific - defining the exact or scaled pixel value.

For example, android:layout_width="15dp" will set the width at a scalable value of 15. You can change 15 to whatever you want. If you want to set a specific pixel size, you can use, for example, 15px.

like image 39
Phil Avatar answered Sep 27 '22 17:09

Phil