Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow opening of MaterialCalendarView

I am using MaterialCalendarView (https://github.com/prolificinteractive/material-calendarview) in my app. It is inside one of my fragments. When I open this fragment, it takes about 2 seconds to load - I can see screen lag. It is really annoying. I have been searching around and found out that this is known problem for CalendarView and I have been trying various fixes: to put it inside FrameLayout, set layout_height to match_parent, set layout_height to fixed height, even put view inside new xml layout file but nothing seems to work for this custom widget. Anyone else had any troubles with this widget?

Here's my layout code:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="net.matto.android.schoolplanner.fragment.CalendarFragment">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2">
            <com.prolificinteractive.materialcalendarview.MaterialCalendarView
                android:id="@+id/calendar_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:mcv_selectionColor="@color/primary_dark"
                app:mcv_firstDayOfWeek="monday"/>
    </FrameLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview_events"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- empty list -->
        <TextView
            android:id="@+id/recyclerview_events_empty"
            android:text="@string/no_events"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingEnd="@dimen/activity_horizontal_margin"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingStart="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/add_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_marginBottom="@dimen/fab_margin_bottom"
            android:layout_marginRight="@dimen/fab_margin_right"
            android:layout_marginEnd="@dimen/fab_margin_right"
            app:borderWidth="0dp"
            android:src="@drawable/ic_plus"
            app:fabSize="normal" />

    </FrameLayout>

</LinearLayout>
like image 851
MaTTo Avatar asked Jul 22 '15 09:07

MaTTo


1 Answers

I hope you are talking about the shaking of the current date that is being set. In order to overcome this issue, just add the following lines of code:

calendarView = (MaterialCalendarView) view.findViewById(R.id.calendarView);
    calendarView.setSelectionMode(MaterialCalendarView.SELECTION_MODE_SINGLE);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            calendarView.setSelectedDate(new Date());
        }
    },1000);

Your shaking will stop.

like image 168
Partha Chakraborty Avatar answered Nov 05 '22 12:11

Partha Chakraborty