android - ActionBarSherlock overlapping fragment in the same tab -


i have problema app.. have change fragment in tab, when new fragment overlap on old fragment. code:

mainactivity:

public class mainactivity extends sherlockfragmentactivity {  viewpager mviewpager; tabsadapter mtabsadapter; textview tabcenter; textview tabtext; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,             windowmanager.layoutparams.flag_fullscreen);      mviewpager = new viewpager(this);     mviewpager.setid(r.id.pager);      setcontentview(mviewpager);     actionbar bar = getsupportactionbar();     bar.setnavigationmode(actionbar.navigation_mode_tabs);     bar.setdisplayoptions(0, actionbar.display_show_title);      mtabsadapter = new tabsadapter(this, mviewpager);      mtabsadapter.addtab(bar.newtab().settext("home"),             fragmenttab1.class, createbundle("ft1"));     mtabsadapter.addtab(bar.newtab().settext("fujisan"),             fragmenttab2.class, null); }  public static class tabsadapter extends fragmentpageradapter implements         actionbar.tablistener, viewpager.onpagechangelistener {     private final context mcontext;     private final actionbar mactionbar;     private final viewpager mviewpager;     private final arraylist<tabinfo> mtabs = new arraylist<tabinfo>();      static final class tabinfo {         private final class<?> clss;         private final bundle args;          tabinfo(class<?> _class, bundle _args) {             clss = _class;             args = _args;         }     }      public tabsadapter(sherlockfragmentactivity activity, viewpager pager) {         super(activity.getsupportfragmentmanager());         mcontext = activity;         mactionbar = activity.getsupportactionbar();         mviewpager = pager;         mviewpager.setadapter(this);         mviewpager.setonpagechangelistener(this);     }      public void addtab(actionbar.tab tab, class<?> clss, bundle args) {         tabinfo info = new tabinfo(clss, args);         tab.settag(info);         tab.settablistener(this);         mtabs.add(info);         mactionbar.addtab(tab);         notifydatasetchanged();     }      @override     public int getcount() {         return mtabs.size();     }      @override     public fragment getitem(int position) {         tabinfo info = mtabs.get(position);         return fragment.instantiate(mcontext, info.clss.getname(),                 info.args);     }      @override     public void onpagescrolled(int position, float positionoffset,             int positionoffsetpixels) {     }      @override     public void onpageselected(int position) {         mactionbar.setselectednavigationitem(position);     }      @override     public void onpagescrollstatechanged(int state) {     }      @override     public void ontabselected(tab tab, fragmenttransaction ft) {         object tag = tab.gettag();         (int = 0; < mtabs.size(); i++) {             if (mtabs.get(i) == tag) {                 mviewpager.setcurrentitem(i);             }         }     }      @override     public void ontabunselected(tab tab, fragmenttransaction ft) {     }      @override     public void ontabreselected(tab tab, fragmenttransaction ft) {     } }  public static bundle createbundle( string title ) {     bundle bundle = new bundle();     bundle.putstring( "title", title );     return bundle; } } 

i have 2 tabs , add 2 fragments. layout:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/home" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"   >  <android.support.v4.view.viewpager     android:id="@+id/pager"     android:layout_width="fill_parent"     android:layout_height="wrap_content" > </android.support.v4.view.viewpager> 

and code of fragmenttab1:

public class fragmenttab1 extends sherlockfragment {  static context context;  @override public sherlockfragmentactivity getsherlockactivity() {     return super.getsherlockactivity(); }  @override public void onviewcreated(view view, bundle savedinstancestate) {     super.onviewcreated(view, savedinstancestate);  }  @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {     relativelayout view = (relativelayout) inflater.inflate(             r.layout.fragmenttab1, container, false);     context = getactivity();      button guasti = (button) view.findviewbyid(r.id.bguasti);     button segnala = (button) view.findviewbyid(r.id.segnaladisservizio);     guasti.setonclicklistener(new onclicklistener() {          @override         public void onclick(view arg0) {              fragment newfragment = new fragmenttab2();             fragmenttransaction transaction = getfragmentmanager()                     .begintransaction();             transaction.replace(r.id.frame1, newfragment, "new frsg");             transaction.addtobackstack(null);             transaction.commit();             getfragmentmanager().executependingtransactions();         }     }); 

with layout have framelayout:

  ...omissis...       <framelayout     android:id="@+id/frame1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentbottom="true"     android:layout_alignparentleft="true"     android:layout_alignparentright="true"     android:layout_alignparenttop="true" >  </framelayout> 

this result: in red thera components of second fragment enter image description here

in xml files, should define background color it, solve problem :

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/home" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" >  <framelayout android:id="@+id/frame1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_alignparenttop="true" > 

add android:background="@android:color/black" in view tag defined.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -