How to reduce size of CalendarView?
Solution 1
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);
Solution 2
There's a couple of different ways you can go about shrinking the size of the CalendarView. One is you can manually adjust the size of the view in the .XML file you're using the calendar in. Another way is by creating a new layout (Such as linear layout), adjust the layout to your desired size, and put the CalendarView in that layout.
Solution 3
Hope this may help to reduce the size of your calendar view.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CalendarView
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/calendarView"
android:firstDayOfWeek="2"/>
</LinearLayout>
<LinearLayout
android:layout_weight="60"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Hello World hello world "
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
Now there is a library which allows you to set the dp size into sdp (Scalable Dp) so that it will help in many screen size
Gradle for that
compile 'com.intuit.sdp:sdp-android:1.0.3'
Code Example Same above example but it will support all possible screen size
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CalendarView
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_100sdp"
android:id="@+id/calendarView"
android:firstDayOfWeek="2"/>
</LinearLayout>
<LinearLayout
android:layout_weight="60"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Hello World hello world "
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
Solution 4
if you want resize
android:scaleY="1.1" -vertically
CHAN HAU YEEN
I am a Master of Information System master's degree holder. I love analysis, logic and teaching. However, I am still new to programming at this old age.
Updated on July 20, 2022Comments
-
CHAN HAU YEEN almost 2 years
May I know how to resize the
CalendarView
in Android? TheCalendarView
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
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 android:layout_width="500dp" android:layout_height="200dp" android:id="@+id/calendarView" android:firstDayOfWeek="2" />