Resizing of DatePicker in android

后端 未结 5 1177
清酒与你
清酒与你 2021-01-11 17:17

How can I reduce the size (height and width) of a DatePicker? Is there any built-in method available for this?

相关标签:
5条回答
  • 2021-01-11 17:41

    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

    0 讨论(0)
  • 2021-01-11 17:47

    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.

    0 讨论(0)
  • 2021-01-11 17:51

    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" />
    
    0 讨论(0)
  • 2021-01-11 17:58

    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"
    />
    0 讨论(0)
  • 2021-01-11 17:58

    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

    0 讨论(0)
提交回复
热议问题