17

I have a huge XML layout, with many Relative / Linear layouts, and what I'm doing now is to hide all the layouts I don't need with setVisibility (View.GONE) and change their visibility when needed.

My question is : is this method sufficient? are the layouts inflated and rendered so they alter the phone memory and it's performances and time of the activity loading or they are not until I set the visibility to VISIBLE.

The layout is getting bigger so I would like to know if I should use Fragments or stay with what I have now.

Adinia
  • 3,722
  • 5
  • 40
  • 58

1 Answers1

25

are the layouts inflated

Yes.

and rendered

No. They are part of the view hierarchy but are ignored in the rendering passes.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Very rightly put. :) Just to add a little to above, **ignored in the rendering passes** means they are there in the layout (exists) but Invisible and do not take any space either. :) – Atul O Holic Apr 28 '14 at 14:59
  • 1
    Thank you. Since they're inflated, the performances of the phone are altered right ? or are they only when the layouts are rendered ? –  Apr 28 '14 at 14:59
  • 12
    @Mehdi: "Since they're inflated, the performances of the phone are altered right ?" -- I do not know what "performances" concern you. `GONE` widgets and containers take up heap space like regular widgets. They are ignored in the rendering passes, so they will not consume much in the way of CPU time, and they should take no GPU time. – CommonsWare Apr 28 '14 at 15:54
  • 1
    @CommonsWare : Thank you. This is exactly what I wanted to know! –  Apr 28 '14 at 16:53
  • 4
    Basically this means `onMeasure`, `onLayout`, and `onDraw` won't get called for the GONE view and it's children. – tir38 Sep 08 '16 at 16:31