2

I have an activity contains a date picker. I want to set DatePicker fit to the screen. I tried this answer. But which not able to give the result i need.

This is my current code:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <DatePicker
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

This is my DatePicker:

enter image description here

I want to make the date picker fill on that green square too.

sabith.ak
  • 255
  • 4
  • 12
  • 1
    Possible duplicate of [How to customize date picker's width and height in android](https://stackoverflow.com/questions/6674667/how-to-customize-date-pickers-width-and-height-in-android) – Goku Nov 24 '17 at 06:34
  • Before asking simple question try to google it, [May Help](https://stackoverflow.com/questions/6674667/how-to-customize-date-pickers-width-and-height-in-android/34523787#34523787) – Mohammed Farhan Nov 24 '17 at 06:40
  • I tried that solution. But which does not strech datepicker to parent layout. @Prem – sabith.ak Nov 24 '17 at 06:49
  • Please try it before you comment @MohammedFarhan – sabith.ak Nov 24 '17 at 06:51

3 Answers3

4

try this ..

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

    <DatePicker
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginTop="37dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:scaleX="1.1"
        android:scaleY="1.1"/>

</RelativeLayout>

output like this..

enter image description here

Vikas singh
  • 3,461
  • 3
  • 14
  • 28
1

you can meet your requirement by adding gravity for parent like like..

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <DatePicker
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>

or else by adding layout_gravity for child as follows

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <DatePicker
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"/>
</LinearLayout>
1

Just use CalendarView instead of DatePicker

John
  • 1,447
  • 15
  • 16