使用长文本时如何减少StaticLayout延迟 [英] How to reduce StaticLayout delay when using long text

查看:218
本文介绍了使用长文本时如何减少StaticLayout延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用StaticLayout对文本进行分页以创建epub应用程序,并且我的文本包含16,000行.

I use StaticLayout to paginate my text to create an epub application, and I have a text that has 16,000 lines.

大约6秒钟后创建了StaticLayout对象,它非常慢.

The StaticLayout object is created about 6 seconds later and it's very slow.

如何减少此时间,或者还有另一种方法来使用StaticLayout?

How can I reduce this time or is there another way to use StaticLayout instead?

推荐答案

问题是您试图一次性布局整个内容.布置16,000行文本很昂贵.即使在具有强大CPU的台式计算机上,这也将花费不小的时间,而您正在尝试在手机上进行.

The problem is that you're trying to lay out the whole thing at once. Laying out 16,000 lines of text is expensive. It's going to take a nontrivial amount of time even on a desktop computer with a powerful CPU, and you're trying to do it on a phone.

相反,请采取渐进的方法.大致估计您希望一页中容纳的文本量-可能是1000个字符.您可以调整此值.进行布局,看是否足够,然后根据需要进行布局.

Instead, take a progressive approach. Take an approximation of the amount of text you expect might fit in one page - maybe 1000 characters. You can tweak this value. Lay that out, see if it's enough, then lay out more if needed.

您可以使用 DynamicLayout 有效地做到这一点.创建它时,请确保将其传递为 Editable 当您添加更多文本时更新布局.

You can use DynamicLayout to do this efficiently. Make sure to pass it an Editable when creating it to allow you to update the layout as you add more text.

这篇关于使用长文本时如何减少StaticLayout延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆