Jeremy
Jeremy

Reputation: 3809

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.

Upvotes: 0

Views: 76

Answers (1)

wsanville
wsanville

Reputation: 37516

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.

Upvotes: 1

Related Questions