Search code examples
androidandroid-tabs

SlidingTabs with only 2 tabs


How can i do that with only 2 tabs and each tab view with 50% screen width? like the current Youtube apps. please help.

The following screenshot (Left) is sample from android (right) is current Youtube app:

enter image description here enter image description here


Solution

  • Only way it's modify source code of SlidingTabLayout.

    To get current window size you could use this method:

    public static Point getWindowSize(Activity ac) {
        Point size;
        Display display = ac.getWindowManager().getDefaultDisplay();
        display.getSize(size);
        return size;
    }
    

    Than in populateTabStrip method add layout params to

    mTabStrip.addView(tabView);
    

    method.

    Smth like this

    width = getWindowSize().x;
    mTabStrip.addView(tabView, 
        new LinearLayout.LayoutParams(width/2, ViewGroup.LayoutParams.WRAP_CONTENT));