While using the hierarchy viewer in order to reduce hierarchies, I\'ve noticed that on each addition of a fragment (both in \"static\" or \"dynamic\" way) the fragments is a
It seems like you are using the support v4 library and you forgot to put and id to your fragment xml tag :), so:
where did it come from?
It comes from line 888 of FragmentManager where you can see this:
f.mView = NoSaveStateFrameLayout.wrap(f.mView);
The reason for this is backwards compatibility and it is better explained in the comment header of NoSaveStateFrameLayout
which says:
/**
* Pre-Honeycomb versions of the platform don't have {@link View#setSaveFromParentEnabled(boolean)},
* so instead we insert this between the view and its parent.
*/
can I get rid of it?
Well, I can think of three options:
FragmentManager
say based on support v4 library version in which you omit this container, but I think the effort of writing/maintaining that code is not worth, plus I don't think the overhead due those FrameLayout
s is gigantic, if you are having performance issues you probably have other View
optimizations to perform besides this (say write a custom view -which extends View
-) or say rethink your layout/fragments to reduce the amount of views in the hierarchy at certain point.FragmentManager
implementation does not have this nested ViewGroup
(see line 861 of 11+ FragmentManager), on those you get something like this:I wouldn't worry much for those as I mentioned there are other optimizations you can invest that time in ;)