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