是“消失"了吗?不利于性能的观点? [英] Are "GONE" views detrimental to performance?

查看:90
本文介绍了是“消失"了吗?不利于性能的观点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个可以节省一些时间的应用程序 具有用于多个活动的单一布局,其中某些视图根据正在使用的活动而设置为消失".

I'm making an app in which it might save me some time to have a single layout for several activities, with some of the views set to GONE depending on which activity is being used.

我知道,在布局中拥有大量视图会导致性能下降.如果我有一个具有大量视图的活动,但是其中大部分视图都已消失,那么该活动的执行效果是否仍然会很差?也就是说,设置为消失"的视图是否会导致性能下降?如果是,它们要求的处理能力是否比可见"或不可见"视图低?

I know that having a large number of views in a layout can lead to poor performance. If I had an activity with a large number of views, but a large portion of those views were to to GONE, would this activity still perform poorly. That is, do views that are set to GONE contribute to worsening performance? If yes, do they demand less processing power than VISIBLE or INVISIBLE views?

谢谢!

推荐答案

关于不可见与不可见的第一件事:

First thing you should know about gone vs invisible:

  • View.GONE该视图是不可见的,并且不占用任何空间用于布局.
  • View.INVISIBLE此视图是不可见的,但仍会占用空间以用于布局.

考虑对测量的影响. 哪个效率更高取决于您的使用频率 更改视图的可见性.

Thinking about the impact on measuring. Which one is more efficient all depends on how frequently you are changing the view's visibility.

例如,如果视图在大部分时间不可见, 使其消失可能会更有效,因为该系统 不会不必要地测量和布置您的隐形视图 每当需要调整屏幕上的其他视图时.

For example, if the view is not visible for a majority of the time, making it GONE would probably be more efficient, because the system would not be needlessly measuring and laying out your invisible view whenever it needs to adjust other views on the screen.

另一方面,如果视图在可见和不可见之间切换 经常,您可能会从INVISIBLE获得更好的性能 可能会避免在每次过渡时都采取额外的措施/布局.

On the other hand, if the view changes between visible and invisible frequently, you might get better performance from INVISIBLE as you would potentially avoid an extra measure/layout on each transition.

这篇关于是“消失"了吗?不利于性能的观点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆