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:
And sure enough, when running on the emulator, the bottom row of dates are cut off:
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>
Just use CalendarView
instead of DatePicker
. It doesn't have that bug.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With