Why Is An Extra Framelayout Created For Fragments?
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 always wrappe
Solution 1:
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:
- You could have your very own implementation of
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 thoseFrameLayout
s is gigantic, if you are having performance issues you probably have otherView
optimizations to perform besides this (say write a custom view -whichextends View
-) or say rethink your layout/fragments to reduce the amount of views in the hierarchy at certain point. - Wait for a new release of support v4 library which accomplishes 1. <- yup I'm a lazy person :D, you'll have to file a bug if there is not one already (see 3.), the cool part of this is you could even contribute your patch or someone else as well.
- Support only platforms (or wait until) where the support v4 library is not (longer) needed, in API level 11+
FragmentManager
implementation does not have this nestedViewGroup
(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 ;)
Post a Comment for "Why Is An Extra Framelayout Created For Fragments?"