Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make DatePicker and TimePicker smaller

Tags:

android

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.

like image 989
Damir Avatar asked Nov 15 '10 01:11

Damir


4 Answers

Use properties follow:

Example smaller 80% original

android:scaleY="0.8" 
android:scaleX="0.8"
like image 161
Huỳnh Ngọc Bang Avatar answered Nov 10 '22 09:11

Huỳnh Ngọc Bang


(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!

like image 24
HaydenKai Avatar answered Nov 10 '22 09:11

HaydenKai


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"

like image 38
Muhammad Shahab Avatar answered Nov 10 '22 08:11

Muhammad Shahab


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>
like image 37
Mar Bar Avatar answered Nov 10 '22 09:11

Mar Bar