简体   繁体   English

声明视图不可见或将背景设置为透明并在需要时更改其背景资源是否更有效?

[英]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? 我试图找出继续进行操作并在xml代码中设置背景资源并将可见性设置为不可见,然后在需要视图时动态地将其动态更改回可见,是否更有效,还是更好地设置背景资源透明并在需要时动态更改后台资源?

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. 如果您担心布局中很少使用很多视图,请查看ViewStub类。 It's basically a placeholder that you can use to lazy initialize views that might not always be required. 从根本上讲,它是一个占位符,可用于懒惰初始化可能不一定需要的视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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