Search code examples
androidsizeandroid-datepicker

Different DatePicker size push buttons out of screen


I have app with DatePicker and my problem is that it have different sizes with different android versions and it push buttons out of screen. Here are images how DatePicker looks on different phones: https://i.sstatic.net/TVqgU.jpg And here is image how to looks like in activity where i have problem with DatePicker size (unfortunately I don't have screen where are buttons are pushed out of screen): https://i.sstatic.net/CxhkC.jpg What is best way, so buttons won't be placed on DatePicker and still be on screen?


Solution

  • You'd have to extend and override some methods of the DatePicker to adjust its layout to your needs. Otherwise, it's not recommended to use it inside your activity alongside other Views. For this reason Google recommends using a DialogFragment to host each time or date picker:

    We recommend that you use DialogFragment to host each time or date picker. The DialogFragment manages the dialog lifecycle for you and allows you to display the pickers in different layout configurations, such as in a basic dialog on handsets or as an embedded part of the layout on large screens.