i have multiple fragments dynamically changing within activity. instances fragments need added in landscape orientation while in portrait. how specify angle @ fragment must added activity ?
my current code:
getfragmentmanager.begintransaction() .setcustomanimations(r.animator.fadein, r.animator.fadeout) .add(r.id.fragment_container, playerpane, tag).commit();
oncreateview method:
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_player_pane, container, false); framelayout.layoutparams params = (framelayout.layoutparams) rootview.getlayoutparams(); // set width height params.height = (getarguments().getint(height)); params.width = (getarguments().getint(width)); params.setmargins((getarguments().getint(left_margin)), (getarguments().getint(top_margin)), (getarguments().getint(right_margin)), (getarguments().getint(bottom_margin))); rootview.setlayoutparams(params); return rootview; }
you can check configuration of device see whether in portrait or landscape , use in if statement launch different fragment.
if (getresources().getconfiguration().orientation == configuration.orientation_portrait) { // launch portrait fragment } else { // launch landscape fragment }
as addition, if writing application, try not change fragment being added depending on orientation, rather have fragment present views differently depending on orientation through use of targeted xml , checks within fragment itself.
Comments
Post a Comment