Change size of one tab in TabLayout on Android

Viewed 64

How I can change the size of one tab in Android TabLayout, I am trying to get all tabs but I am not able to modify tab size. I want to make the middle one larger.

I have tried to tab.setMinimumWidth but it is not working as expected. Check this image

final Toolbar toolbar = findViewById(R.id.htab_toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) getSupportActionBar().setTitle("Parallax Tabs");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final ViewPager viewPager = findViewById(R.id.htab_viewpager);
    setupViewPager(viewPager);
    TabLayout tabLayout = findViewById(R.id.htab_tabs);
    tabLayout.setupWithViewPager(viewPager);
    TabLayout.Tab mtab = tabLayout.getTabAt(2);
    mtab.select();

    ViewGroup tabs = (ViewGroup) tabLayout.getChildAt(0);

    for (int i = 0; i < tabs.getChildCount() - 1; i++) {
        View tab = tabs.getChildAt(i);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)     tab.getLayoutParams();

        layoutParams.setMarginEnd(20);
        layoutParams.setMarginEnd(20);
        layoutParams.width = 10;

        tab.setLayoutParams(layoutParams);

        if(i==2)
        {

            tab.setMinimumWidth(100);
            tab.setMinimumHeight(200);
        }
        else
        {
            tab.setMinimumWidth(50);
            tab.setMinimumHeight(50);
        }
        tabLayout.requestLayout();
    }
0 Answers
Related