问题
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