Tab not taking full width on Tablet device [Using android.support.design.widget.TabLayout]

前端 未结 12 2111
萌比男神i
萌比男神i 2020-11-28 17:39

I have setup tabs as UPDATE 29/05/2015 this post. Tabs take full width on my Nexus 4 mobile but on nexus 7 tablet it in center and not cover full screen wid

12条回答
  •  死守一世寂寞
    2020-11-28 18:30

    Solution for Scrollable (Kotlin)

    In xml:

         
    

    In Kotlin:

    In my case if less than 3 tabs I allocate equal space.

    Note: If condition is as per your requirement

            if(list.size <= 3){
              allotEachTabWithEqualWidth(your_tab_layout)
            }
    
         fun allotEachTabWithEqualWidth(tabLayout: TabLayout) {
            mTabLayout.tabMode=  TabLayout.MODE_FIXED
            val slidingTabStrip = tabLayout.getChildAt(0) as ViewGroup
            for (i in 0 until tabLayout.getTabCount()) {
                val tab = slidingTabStrip.getChildAt(i)
                val layoutParams = tab.layoutParams as LinearLayout.LayoutParams
                layoutParams.weight = 1f
                tab.layoutParams = layoutParams
            }
    
        }
    

提交回复
热议问题