问题描述
这是推动我疯了。我在我的Android应用程序的片段是奠定了使用RelativeLayout的。问题是,由于某种原因,它需要年龄渲染,大约5秒的时间来加载约4个元素在屏幕上。
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.
一个元素是CalendarView,当我删除它,又回到正常速度(即:瞬发)。我想像的问题有什么关系,我问的Android奠定它的出路,一定没有多大意义或者是低效或东西。
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.
下面的XML文件:
<?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.
任何见解将大大AP preciated。谢谢
Any insights would be greatly appreciated. Thanks
推荐答案
我有这个问题太多,既相对布局和线性布局。它似乎并没有被布置有关。
I've had this problem too, both with relative layouts and linear layouts. It doesn't seem to be layout-related.
下面是一个例子,看看错误,只需用一个简单的布局,没有code在所有的:
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"
通过这种变化的问题消失了,至少在我的三星Galaxy Tab 2
With this change the problem is gone, at least in my Samsung Galaxy Tab 2
所以,现在看来,这是更多的空间有关,但我仍然不知道为什么会出现这个问题。而且我还没有发现其他有趣的结果在谷歌搜索calendarview慢......
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"...
修改的让我们看看我们是否能够找到一个小的赏金答案的
这篇关于Android的CalendarView放缓布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!