Are “GONE” views detrimental to performance?

前端 未结 2 1245
再見小時候
再見小時候 2021-02-03 18:07

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 us

2条回答
  •  梦如初夏
    2021-02-03 19:06

    First thing you should know about gone vs invisible:

    • View.GONE This view is invisible, and it doesn't take any space for layout purposes.
    • View.INVISIBLE This view is invisible, but it still takes up space for layout purposes.

    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.

    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.

提交回复
热议问题