gpt4 book ai didi

Android:构建包含大量元素的 View 非常慢(超过 10 秒)

转载 作者:搜寻专家 更新时间:2023-11-01 07:39:55 25 4
gpt4 key购买 nike

首先:我最近才开始为 Android 开发,所以请不要因为我提出愚蠢/明显的问题而向我扔东西! ;D

我遇到的问题如下:我想显示一个未知长度的可点击项目列表——我的示例数据集大约有 300 个。使用 LinearLayout 并将它们全部添加为 TextViews 在模拟器上大约需要半秒钟,这完全没问题。为了增强用户体验,我现在将 LinearLayouts 替换为 Relative Layouts,每个布局都有一个背景图像、2 个 TextView 和 3 个 ImageView。所有图片都包含在资源中,因此不会浪费时间进行下载等。

问题是:现在构建这个 View 大约需要 10 秒,这显然不是可行的解决方案。我的假设是完整的 UI 是完全构建的,尽管它总是只有一部分可见(使用一些滚动容器)

因为我懒得编写逻辑来手动确保只有 UI 的可见部分被实际填充,我想知道是否有人知道这个问题的一些简单的标准解决方案。

是否有某种我必须激活的 UI 代理?或者您会建议使用前 10 个元素来创建屏幕,然后在单独的线程中在后台加载其他元素吗? (不知道滚动容器 - 或一般的 android 用户界面 - 会如何对此使用react)

提前感谢所有帮助! =)

长话短说:构建大 View 的方式太慢 - 需要帮助! 小狗的眼睛

最佳答案

I want to display a list of clickable items of unknown length - my sample data set is around 300

使用 ListViewAdapterView 的任何其他子类。

My assumption would be that the complete UI is completely built despite only always a part of it being visible (using some scroll container)

这就是 AdapterView 子类(如 ListView)的作用——只为可见的部分创建小部件,而不是为整个数据模型创建小部件。

As I am far too lazy to write logic to manually make sure only the visible part of the UI is actually populated, I was wondering if anyone knows of some simple standard solution for this problem.

使用 ListViewAdapterView 的任何其他子类。

Is there some sort of UI proxies I simply have to activate?

没有。

Or would you recommend creating the screen with like the first 10 elements and load the others in the background in a separate Thread?

没有。主要是因为你会崩溃。您只能从主应用程序线程修改 UI,而不能从您派生的后台线程修改。

关于Android:构建包含大量元素的 View 非常慢(超过 10 秒),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5358827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com