How to reduce size of CalendarView?

CHAN HAU YEEN picture CHAN HAU YEEN · Sep 18, 2016 · Viewed 9k times · Source

May I know how to resize the CalendarView in Android? The CalendarView occupied more than half of the screen. I wish to make it smaller, perhaps 40% of the screen. Thanks.

Default CalendarView size in my smartphone, occupied more than half

CalendarView

My current XML:

<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"
tools:context="com.ada.landing.MainActivity">

<CalendarView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/calendarView"
    android:firstDayOfWeek="2"/></RelativeLayout>

I tried another way to define CalendarView, but the overall height reduced but it does not shrink by ratio:

CalendarView

<CalendarView
            android:layout_width="500dp"
            android:layout_height="200dp"
            android:id="@+id/calendarView"
            android:firstDayOfWeek="2" />

Answer

Cocorico picture Cocorico · May 19, 2017

I think CalendarView is not (really) resizeable because Android adapts the size of this view to allow user to have a great experience using this view. I think the commun size is when use a DatePickerDialog. DatePickerDialog

CalendarView needs a minimum height and width.

If you really want to resize your calendarView, maybe try to resize(or scale) it programmatically with this :

float scalingFactor = 0.5f; // scale down to half the size view.setScaleX(scalingFactor); view.setScaleY(scalingFactor);