7

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>
7
  • can you post your XML code? Oct 29, 2017 at 23:26
  • The calendar view is in a ScrollView if I'm correct. Did you try scrolling them up / down? Oct 30, 2017 at 3:29
  • I'm not sure if it is in a ScrollView under the hood, but I do not have it in a ScrollView. I tried scrolling on the calendar but I am unable to scroll it up/down.
    – rsteilberg
    Oct 30, 2017 at 5:31
  • Also @YunusKulyyev my XML code is posted above.
    – rsteilberg
    Oct 30, 2017 at 5:31
  • Where is your calendar date picker. The one that you have posted is only for the spinner picker Oct 30, 2017 at 6:32

2 Answers 2

1

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

1

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);

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.