CalendarView takes a long time to display

I am working on an application in CalendarView. I have to show calendarView in a small linear layout.

There is a problem when displaying an entire page that contains calendarView in a small linear layout. -> it takes 10 seconds to show & this is a lot of time ...

there is no other thing in the layout.

here is my xml and binding ...

any help would be greatly appriciated ...

<?xml version="1.0" encoding="utf-8"?> <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="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="vertical" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="30" android:paddingLeft="30dp" > <TextView android:id="@+id/txtDate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My Calendar" android:textSize="50sp" /> <View android:layout_width="fill_parent" android:layout_height="2dp" android:layout_alignParentBottom="true" android:layout_marginBottom="40dp" android:layout_marginRight="30dp" android:background="@android:color/black" /> </RelativeLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="70" android:paddingBottom="30dp" android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingTop="30dp" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical" > <ListView android:id="@+id/list_task" android:layout_width="fill_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout> </RelativeLayout> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="vertical" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="30" > <CalendarView android:id="@+id/cal_small" android:layout_width="250dp" android:layout_height="250dp" android:layout_centerHorizontal="true" android:background="@android:color/darker_gray" android:showWeekNumber="false" android:animateLayoutChanges="false" android:clipChildren="false" android:drawingCacheQuality="low" android:soundEffectsEnabled="false" android:hapticFeedbackEnabled="false" /> <View android:layout_width="fill_parent" android:layout_height="2dp" android:layout_alignParentBottom="true" android:layout_marginBottom="40dp" android:layout_marginLeft="30dp" android:layout_marginRight="30dp" android:background="@android:color/black" /> </RelativeLayout> <RelativeLayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="70" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginBottom="30dp" android:layout_marginRight="10dp" android:layout_marginTop="30dp" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="8" > <ListView android:id="@+id/list1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="30dp" > </ListView> </LinearLayout> <ListView android:layout_width="wrap_content" android:layout_height="wrap_content" > </ListView> </LinearLayout> </RelativeLayout> </LinearLayout> </LinearLayout> </LinearLayout> 

enter image description here

+6
source share
4 answers

It seems very simple, but by chance I checked it and it works well. Hope this also helps you ...

First, create a separate XML file that contains only CalendarView. Named "cal_view.xml"

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <android.widget.CalendarView android:layout_width="200dp" android:layout_height="200dp" /> </LinearLayout> 

Then include this xml file in the main xml file, like the following. Instead of your CalanderView, include the xml file.

  <include android:id="@+id/subCategory" layout="@layout/cal_view" /> 
+10
source

As you mentioned your problem,

Questions

Your XML resource file (layout) is not an optimal way. Since the manual for Android does not use static heights and weights for the ViewGroup. Please read http://developer.android.com/training/improving-layouts/optimizing-layout.html

Decision:

In my opinion, you should create your own class to create a calendar view. In which you apply all the properties and attribute.

I am showing a demo application for presenting Calender. http://www.androidviews.net/2013/01/ics-calendarview/ There is a better way to use the calendar view in this application. also i mention some git url for another custom calendar view

In the above application showing the correct way to use CalendarView

Here I show a screenshot for the Calenderview app

enter image description hereenter image description hereenter image description here

If there is any problem, please let me know, I will create a sample demo for the same.

+1
source

None of the above answers worked for me, I just changed the width and height to "fill_parent", and now everything works fine for me.

 <CalendarView android:layout_width="fill_parent" android:layout_height="fill_parent"/> 
+1
source

Including CalendarView in FrameLayout solves the problem. I tested it and it works great without glitshing.

Here is an example XML code:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#cc00b1cc"> <FrameLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="102dp" android:layout_alignParentBottom="true"> <CalendarView android:layout_width="425dp" android:layout_height="374dp" android:id="@+id/calendarView" android:layout_gravity="left|top" /> </FrameLayout> </RelativeLayout> 
0
source

Source: https://habr.com/ru/post/953571/


All Articles