android - Design Library TabLayout, tab indicator bouncing after scroll -


edit latest design libraries fixed issue

compile 'com.android.support:design:+'


i working tablayout in 2 instances, pageradapter , fragmentstatepageradapter. in both cases tab indicator bounces, when swiped between pages. tab indicator doesn't bounce when clicking tab's change pages.

i not sure if error on part, known issue, or part of guidelines. if need more code, or other example post it.

fragmentstatepageradapter

    mviewpager.setadapter(new fragmentstatepageradapter(getsupportfragmentmanager()) {         @override         public fragment getitem(int position) {             logmeal log = mlogmealadapter.getitem(position);             return mealviewfragment.newinstance(log.getid());         }          @override         public charsequence getpagetitle(int position) { // tab text             logmeal logmeal1 = mlogmealadapter.getitem(position);             string s;             if (logmeal1.getmealname().tostring().trim().length() > 12) {                 s = logmeal1.getmealname().substring(0, 12) + "..";             } else {                 s = logmeal1.getmealname();             }             return s;         }          @override         public int getcount() {             return mlogmealadapter.getcount();         }     });      tabs.settabtextcolors(color.parsecolor("#80ffffff"), color.parsecolor("#ffffff"));     if (mlogmealadapter.getcount() == 1) {         tabs.settabmode(tablayout.mode_fixed);     } else {         tabs.settabmode(tablayout.mode_scrollable);     }     tabs.setupwithviewpager(mviewpager);     mviewpager.setcurrentitem(position); 

xml

<relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent">      <android.support.v7.widget.toolbar         android:id="@+id/toolbar_meal_view"         android:layout_width="match_parent"         android:layout_height="56dp"         android:background="@color/primary"         app:theme="@style/themeoverlay.appcompat.dark.actionbar"/>      <android.support.design.widget.tablayout         android:id="@+id/tabs"         android:layout_width="match_parent"         android:layout_height="48dp"         android:layout_below="@+id/toolbar_meal_view"         android:background="@color/primary"         android:theme="@style/toolbartheme"/>      <android.support.v4.view.viewpager         android:id="@+id/pager"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_below="@+id/tabs"/>      <linearlayout         android:layout_width="match_parent"         android:layout_height="10dp"         android:layout_below="@+id/tabs"         android:background="@drawable/toolbar_shadow"/>  </relativelayout> 

i had similar problem recently.
workaround:

1) change tabs.setupwithviewpager(mviewpager); for

    \\ use own onpagechangelistener      mviewpager.addonpagechangelistener(new mypagescrolllistener(mtablayout));        \\ manually add tabs, example:       mtablayout.addtab(mtablayout.newtab().settext(mviewpager.getadapter().getpagetitle(0)));     mtablayout.addtab(mtablayout.newtab().settext(mviewpager.getadapter().getpagetitle(1)));        \\ use own ontabselectedlistener       mtablayout.setontabselectedlistener(new myontabselectedlistener());   

2) add implementation custom listeners

 private class mypagescrolllistener implements viewpager.onpagechangelistener {     private tablayout mtablayout;      public mypagescrolllistener(tablayout tablayout) {         this.mtablayout = tablayout;     }      @override     public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) {      }      @override     public void onpageselected(int position) {         if(mtablayout != null) {             mtablayout.gettabat(position).select();         }     }      @override     public void onpagescrollstatechanged(int state) {      } }  private class myontabselectedlistener implements tablayout.ontabselectedlistener {     @override     public void ontabselected(tablayout.tab tab) {         int position = tab.getposition();         if (mviewpager.getcurrentitem() != position) {             mviewpager.setcurrentitem(position, true);         }     }      @override     public void ontabunselected(tablayout.tab tab) {      }      @override     public void ontabreselected(tablayout.tab tab) {      } } 

i hope helps.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -