Search code examples
androidandroid-viewpagerpagerslidingtabstrip

SlidingTabLayout setDistributeEvenly missing


I'm using the SlidingTabLayout.java from developers android page. Before I used slidingTabLayout.setDistributeEvenly(true); to center the slidingtab but now the method is missing. What's the alternative? I could use the old java class but I suppose there is an alternative method to do the same thing.


Solution

  • In your SlidingTabLayout add the following:

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f);
    tabView.setLayoutParams(lp);
    

    just before

    mTabStrip.addView(tabView);
    

    After that you won't even need slidingTabLayout.setDistributeEvenly(true); the tabs will automatically center themselves.