android - How to handle orientation change in fragment in viewpager programmatically? -
i have 3 fragments,only 1 of them must change orientation(but not activity), activiy has flag congifchanges="orientation|screensize"
, , viewpager
. want change layouts programmatically on every orientation change.
i have 2 different layouts, if scroll pages on viewpager, layout change expected.
what have:
what want:
as in such situations, seems decision should difficult implement. in fact, 3 lines:
@override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); viewgroup viewgroup = (viewgroup) getview(); viewgroup.removeallviewsinlayout(); view view = oncreateview(getactivity().getlayoutinflater(), viewgroup, null); viewgroup.addview(view); }
here found it
redrawing fragment not best idea if keeps data (plays video, map, etc.) because have no dynamically changing data there, , had show same thing, in different orientation, used approach if need change orientation , did not lose data must read this.
Comments
Post a Comment