This is driving me crazy. I have a fragment in my Android app which is laid out using a RelativeLayout. Problem is that for some reason it takes ages to render, about 5 seconds just to load about 4 elements on screen.
One of the elements is a CalendarView and when I remove it it goes back to proper speeds (ie: instant). I'd imagine the problem is got to do with the way I'm asking Android to lay it out, must not make much sense or is inefficient or something.
Here's the XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="TODAY"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/time" />
<TextView
android:id="@id/time"
android:gravity="right"
android:textStyle="bold"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="11:32"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignParentRight="true" />
<TextView
android:id="@+id/date_info"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wednesday, 15th August 2012"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_below="@id/title"
android:layout_alignParentLeft="true" />
<CalendarView
android:id="@+id/calendar_view"
android:layout_width="250dp"
android:layout_height="250dp"
android:background="@drawable/white_back_black_border"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
I've tried loads of different layout options but removing the Calendar seems to be the only thing that makes a difference.
Any insights would be greatly appreciated. Thanks
Found that CalendarView widget needs height to be set to
match_parent
, then you can put it to any layout. For example in relative with height 200. This works fine on 4.0.3 emulator and on Samsung Galaxy Tab with 4.2.2.The above answers were right but, still hasn't solved one mystery.
That is, When i want to include calendarview inside layout with other layout. It's just disappears or i can see only Week letters. I tried the above match parent and everything and still i couldn't solve it.
If anyone struggling like me Here's the answer.
I take some hours to find the answer, but not figure out why. Here is something strange, may it can help you to find the answer.
The getView in WeekAdapter has a param parent that was never used.
Looking forward the answer.
Putting the CalendarView in a FrameLayout will solve the problem.. here is a XML code example:
I've had this problem too, both with relative layouts and linear layouts. It doesn't seem to be layout-related.
Here is an example to see the error, just with a simple layout, no code at all:
And now just change the linear layout height to:
With this change the problem is gone, at least in my Samsung Galaxy Tab 2
So it seems it is more "space" related, but I'm still not sure why this problem appears. And I haven't found any other interesting results on google searching "calendarview slow"...
EDIT Let's see if we can find an answer with a small bounty
It seems like CalendarView directly inside a RelativeLayout really doesn't work that well. The following solution with the trick of using a FrameLayout is loading much faster in the emulator: