Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DatePicker days cut off

I am trying to have a AlertDialog modal with a DatePicker inside of it. However, when I add the DatePicker to the modal in the editor, the bottom dates are cut off: enter image description here

And sure enough, when running on the emulator, the bottom row of dates are cut off:

enter image description here

I've tried making the padding and margin and even height greater but nothing works.

EDIT: Below is my XML code for the modal with the DatePicker.

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.constraint.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <DatePicker
        android:id="@+id/dose_date_picker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:datePickerMode="spinner"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="8dp" />
</android.support.constraint.ConstraintLayout>
like image 364
rsteilberg Avatar asked Oct 29 '17 22:10

rsteilberg


2 Answers

Just use CalendarView instead of DatePicker. It doesn't have that bug.

like image 53
davee44 Avatar answered Oct 20 '22 10:10

davee44


Found a working solution to this. A little description of the problem here. DatePicker uses this layout for calendar view:

    <CalendarView
        android:id="@+id/calendar_view"
        android:layout_width="245dip"
        android:layout_height="280dip"

Basically a fixed width and height. This used to work correctly with the holo theme i.e. android:Theme.Holo.Light since it uses a legacy xml layout, but with appcompat theme or material theme, it started to cut off the last line in the calendar, since they're using a different layout.

The solution is to update the calendarview height programmatically and make it wrap content.

CalendarView cv = datePicker.getCalendarView();
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) cv.getLayoutParams();
params.height = LinearLayout.LayoutParams.WRAP_CONTENT; // Or 300dp
cv.setLayoutParams(params);
like image 45
Shivam Pokhriyal Avatar answered Oct 20 '22 09:10

Shivam Pokhriyal