Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
938 views
in Technique[技术] by (71.8m points)

performance - Android CalendarView slowing down layout

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".FechaHoraActivity" >

    <TimePicker
        android:id="@+id/timePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp" />

    <CalendarView
        android:id="@+id/calendarView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

And now just change the linear layout height to:

android:layout_height="match_parent"

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...