Warning: this may be the answer before the candy.
A Fragment will not be overestimated when changing the configuration, but you can achieve the effect as follows by creating it using FrameLayout and (re), which will be entered manually:
public class MyFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { FrameLayout frameLayout = new FrameLayout(getActivity()); populateViewForOrientation(inflater, frameLayout); return frameLayout; } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); LayoutInflater inflater = LayoutInflater.from(getActivity()); populateViewForOrientation(inflater, (ViewGroup) getView()); } private void populateViewForOrientation(LayoutInflater inflater, ViewGroup viewGroup) { viewGroup.removeAllViewsInLayout(); View subview = inflater.inflate(R.layout.my_fragment, viewGroup);
I'm not particularly happy with getActivity() and the calls related here, but I don't think there is another way to get hold of these things.
Update: Removed non- ViewGroup to FrameLayout and uses LayoutInflater.from() , and the third parameter is inflate() instead of an explicit view.
source share