17

As far as I undestand, neither a ViewStub nor a View that's GONE participate in the measure and layout passes (or rendering anyway).

Is there a difference in rendering performance? What's the best practice about when to use which?

mxk
  • 43,056
  • 28
  • 105
  • 132

1 Answers1

5

The rendering performance comes into picture when you are inflating the views.

My guess is that its much cheaper to inflate a ViewStub than to inflate a View, either from XML or by changing visibility. ViewStub is especially used when you need to add/remove (indefinite) views (eg. add phone numbers to a given contact). Hope this is what you were looking for.

Sameer Segal
  • 21,813
  • 7
  • 42
  • 56
  • 2
    isn't inflating a ViewStub equivalent to inflating the view that the ViewStub stubs (hey cool, say that 3 times in a row!)? – mxk Aug 19 '10 at 20:44
  • Too many views - too many stubs! ;). I don't think so. I vaguely remember reading something about it. Documentation: "lazily inflate layout resources at runtime; ViewStub exists in the view hierarchy" -- I guess this implies its much cheaper to inflate a ViewStub than to inflate a View. – Sameer Segal Aug 20 '10 at 04:20
  • 4
    In other words, as long as a ViewStub has not yet been inflated, it's faster to render than a view that's GONE, correct? Plus, when it actually has to be inflated, inflation is cheaper than a "normal" inflation? – mxk Aug 20 '10 at 09:21