dev
dev

Reputation: 11309

Are views with visibility set to "gone" part of measure and layout passes?

I have 3 layouts in my root layout. Only one of these layouts would be "visible" and rest 2 would be "gone". Since all these layouts are bulky, I am concerned :

  1. Do all 3 layouts consume memory after I inflate the root xml ?
  2. Every time the viewgroup invalidates or requests layout, are all the viewgroups measured and drawn, or just the "visible" ones ?

Additional details (if needed) - I am implementing a chat window which has 3 states - expanded, collapsed and multiple. This chat window popup will be at the bottom of all screens in my app, and the user can expand to chat. All 3 states are much more than an imageview + textview, so I went for 3 different layouts (for every state) and only 1 of them is visible at a time. I don't know if there is a better approach for achieving this.

Upvotes: 1

Views: 2173

Answers (1)

Martin Cazares
Martin Cazares

Reputation: 13705

1.- Yes all your Views will consume memory, even GONE views, the only difference is that those views will not be measured or draw, but they are still usable on the View and ready to be shown just by calling setVisibility, so they actually are loaded in memory, If you need a View that will not be fully loaded until specified look at the ViewStub

2.- Just the visible ones, but once again, the GONE views, are loaded in memory just not Measured-Drawn, in case you might wonder the difference between INVISIBLE and GONE, INVISIBLE will take the measured space but not visible and GONE will not take that space...

Hope it Helps!

Regards!

Upvotes: 7

Related Questions