android - Conditionally apply padding to Fragment when switching Fragments -


my activity first displays webview fragment must have 0 padding webview touches edges of screen. transitions scrollview fragment must have 12dp padding inside scrollview (and not activity) scroll bars @ edge content padded. if scrollview fragment part of two-pane activity layout, left side must padded.

you try this:

@override public void onstart() {     super.onstart();      if(getresources().getconfiguration().orientation == configuration.orientation_landscape) {         //modify padding     }  } 

edit:

let's have first fragment showing list of items, , second fragment showing details, code, reusing detailsfragment instance if exists.

public boolean multipane() {     return getresources().getconfiguration().orientation == configuration.orientation_landscape; }  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      if(multipane()) {         detailsfragment details = (detailsfragment)getsupportfragmentmanager().findfragmentbytag("details_fragment");         if (details != null) {             getsupportfragmentmanager().popbackstackimmediate(null, fragmentmanager.pop_back_stack_inclusive);             getsupportfragmentmanager().begintransaction().remove(details).commit();             getsupportfragmentmanager().executependingtransactions();             getsupportfragmentmanager().begintransaction().replace(r.id.multi_details, details, "details_fragment").commit();         } else {             //create , show default details fragment(e.g. first itme on list idk)         }     } else {         mylistfragment lf = new mylistfragment();         getsupportfragmentmanager().begintransaction().replace(r.id.list_and_details, lf, "list_fragment").commit();     }  } 

this part of code used avoid exception when changing detailsfragment 1 framelayout container(portrait xml) another(landscape xml).

getsupportfragmentmanager().popbackstackimmediate(null, fragmentmanager.pop_back_stack_inclusive); getsupportfragmentmanager().begintransaction().remove(details).commit(); getsupportfragmentmanager().executependingtransactions(); 

the exception is:

...java.lang.illegalstateexception: can't change container id of fragment detailsfragment... 

it's pretty basic example


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -