How to reduce StaticLayout delay when using long text

给你一囗甜甜゛ 提交于 2020-06-23 03:32:39

问题


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

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

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


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/61508064/how-to-reduce-staticlayout-delay-when-using-long-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!