1

我有一个 Android 游戏,其中包含一个屏幕,其中列出了所有正在进行的游戏、简短描述、对手名称和个人资料图片等。与 Zynga 的 With Friends 游戏非常相似。但是,当您有数十个正在进行的游戏都必须列出时,我总是在渲染游戏列表时遇到巨大的性能问题。

由于加载时间可能超过 5 秒,我认为是时候进行一些分析并找出瓶颈了。事实证明,大约 70% 的时间用于膨胀和初始化布局元素(这些元素已被最小化为尽可能平坦和轻巧),所以即使我可以优化其余代码以立即发生,加载从用户体验的角度来看,时间仍然是不可接受的。

由于额外的 UI 元素(例如按钮等)不遵循与游戏相同的模板,因此简单的 ListView 将无法工作。在 iOS 上,类似的结构几乎可以立即呈现,即使在 3GS 上也是如此,所以我希望类似动力的 Android 设备至少具有类似的速度。我有哪些选择可以减少用于布局膨胀和初始化的时间?

(如果您不知道它的样子,请参考与朋友的对话截图)在此处输入图像描述

4

1 回答 1

3

You should look at this conference about ListView. It teach how to implement it on a good way, doing as a minimum of allocation as possible. The content that could interest you begins at the 9th minute.

  • The first topic is to use the convetView provided by the getView function
  • The second one is to use a ViewHolder to improve the access speed

Another thing, you should try to manage your image loading to be sure that part is not blocking the rendering for a while.

There is a good tool to profile your application, to know what are the laggy functions in your code : look at that here

于 2012-07-20T23:42:03.267 回答