简体   繁体   中英

Is it more efficient to declare a view invisible or set the background to transparent and change it's background resource when needed?

Trying to get the most of my app means making more efficient code to help the user have a better experience. So I was wandering if anyone could help me and let me know which is a better choice for efficiency.

I have views which come to life at various times in the program through animations but their places are still held in the main layout so the buttons are constantly in existence. I was trying to figure out whether it's more efficient to go ahead and set the background resources in the xml code and just set the visibility to invisible and then change it back to visible dynamically when the views are needed, or is better to set the background resource to transparent and change the background resource when needed dynamically?

I'm aware the difference is minimal but when trying to use an app the most frustrating thing can be speed so knocking off even a quarter of a second in loading time is a step towards more efficient and more complete experience for the user.

If you're concerned about having many views in your layout that are seldom used, check out the ViewStub class. It's basically a placeholder that you can use to lazy initialize views that might not always be required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM