Android:高度和内存消耗为0的视图
比方说,我有一个视图,并且有一个算法,当视图滚动到屏幕外时,该算法会导致视图的高度变为 0。该视图是否仍然消耗与全尺寸相同的内存量?我想我应该对 View.INVISIBLE 或 View.GONE 问同样的问题?
Let's say for example that I have a view and I have an algorithm that causes the View's height to become 0 when it scrolls off screen. Does this View still consume the same amount of memory as it would if it were full size? I guess I should ask the same question for View.INVISIBLE or View.GONE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的 -
View
是一个Object
,只要任何Object
存在(无论它是否是 UI 对象),它都会使用完全相同的数量的记忆。当 OOP 环境中的对象不再存在时(它被销毁/取消引用并被垃圾收集),那么它根本不使用任何内存。中间没有太多的事情。使 UI 对象不可见或将其宽度/高度尺寸减小到 0 仅意味着 GPU 不必以相同的方式处理它,无论它是否在屏幕上。
Yes - a
View
is anObject
and as long as anyObject
exists (whether it's a UI object or not) it uses exactly the same amount of memory. At the point anObject
in an OOP environment ceases to exist (it's destroyed / de-referenced and garbage collected) then it uses no memory at all. There isn't very much in-between.Making a UI object invisible or reducing its size in width/height to 0 will simply mean the GPU won't have to process it in the same way regardless of whether it is on screen or off.