Can I create UI outside main thread (UI Thread)?

℡╲_俬逩灬. 提交于 2019-12-11 04:35:37

问题


my UI is pretty long to generate (about 20 seconds) for good reasons (calculating measurements of hundreds of views). I (think?) have to create them in the main thread, and then I run a progressdialog to make the user wait. Though, the main thread is already overloaded by the creation of the other calculations. Could I then create UI outside the main thread though I have to get measurements of several views?


回答1:


While some people say that they have got it to work, both Dianne and Romain say that you should not do this in a discussion, as the entire UI tree is single threaded. They say that it is not guaranteed to work, and should be avoided.

I can't come up with any scenario in which you'd need hundreds of Views instantiated and drawn at the same time. Perhaps you need to use a ListView, or implement some kind of lazy loading in your app.



来源:https://stackoverflow.com/questions/15909411/can-i-create-ui-outside-main-thread-ui-thread

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