Android Fragments orientation problem
i have implemented different layouts for a fragment for portrait and landscape orientation.
I have a TabActivity with 3 tabs that have the fragments in them.
I have then implemented the onConfigurationChanged method of the Fragment and in there i am removing the current Fragment and readding it (the only way to let it inflate the correct layout, right?).
Unfortunately this only seems to be working for the currently visible Fragment.
Example: 1) All Fragments are initialized with portrait layout, everything is fine 2) I change to landscape 3) Visible Fragment changes fine, landscape layout is loaded 4) The two Fragments that were not visible when the orientation change happended have loaded their portrait layouts
On all three Fragments, the onCreateView method has been called.
开发者_如何学编程Any ideas why invisible Fragments behave different then visible Fragments?
This is the code that i am using:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.d("PhotoFragment", "onConfigurationChanged");
FragmentTransaction transaction = getFragmentManager()
.beginTransaction();
transaction.remove(this);
transaction.add(R.id.fragment_container, new PhotoFragment(mPhoto));
transaction.addToBackStack(null);
transaction.commit();
getFragmentManager().popBackStack();
}
精彩评论