Android CalendarView 减慢布局

标签 android performance android-layout android-xml calendarview

这快把我逼疯了。我的 Android 应用程序中有一个 fragment ,它使用相对布局进行布局。问题是由于某种原因渲染需要很长时间,大约 5 秒才能在屏幕上加载大约 4 个元素。

其中一个元素是 CalendarView,当我删除它时,它会恢复到适当的速度(即:即时)。我想这个问题与我要求 Android 布置它的方式有关,一定没有多大意义或效率低下或其他什么。

这是 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>

我已经尝试了许多不同的布局选项,但删除日历似乎是唯一有所作为的事情。

任何见解将不胜感激。谢谢

最佳答案

我也遇到过这个问题,无论是相对布局还是线性布局。它似乎与布局无关。

这里是一个看错误的例子,只是布局简单,完全没有代码:

<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>

现在只需将线性布局高度更改为:

android:layout_height="match_parent"

有了这个改变,问题就消失了,至少在我的三星 Galaxy Tab 2 中

所以它似乎更多地与“空间”相关,但我仍然不确定为什么会出现这个问题。而且我在谷歌搜索“calendarview slow”时没有找到任何其他有趣的结果......

编辑 让我们看看能不能用小额赏金找到答案

关于Android CalendarView 减慢布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13812084/

相关文章:

php - 在文章索引中计算文章评论、点击和喜欢的正确方法是什么?

javascript - jQuery:递归过多且超出最大调用堆栈大小

java - Android 发布/订阅单例示例

Nexus4 与 Nexus 7 的 Android 布局

android - Android应用程序的自动化测试工具

android - 如何在 X 秒后发送延迟的 BroadcastReceiver

python - bool 值的大列表和小列表以及字节数组的相对性能

java - 如何动态移动布局?

android - 为什么 BluetoothGattCallback 会在几秒钟后不断断开连接?

android - 是否有可能从 fragment 中获取 `RecyclerView`?