how to override height and width of date picker to fill the parent layout

大城市里の小女人 提交于 2019-12-13 04:10:42

问题


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:

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


回答1:


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..




回答2:


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>



回答3:


Just use CalendarView instead of DatePicker



来源:https://stackoverflow.com/questions/47467550/how-to-override-height-and-width-of-date-picker-to-fill-the-parent-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!