TabLayout的不同选项卡宽度

问题描述:

我正在使用TabLayout& ViewPager. 我正在尝试更改选项卡的大小,例如Whatsapp(相机图标). 三个选项卡的大小相等,但相机的选项卡较小. 在每次尝试中,我都使选项卡的大小保持不变(所有选项卡均相等). 谢谢.

I'm using TabLayout & ViewPager. I am trying to change the size of the Tab, like Whatsapp (camera icon). The size of the three Tabs is equal, but the Tab of the camera is smaller. In every attempt I make the size of the Tabs remains the same (equal across all tabs). Thanks.

您需要降低相应选项卡的LinearLayout的权重.

You need to lower the weight of the LinearLayout of the corresponding tab.

LinearLayout layout = ((LinearLayout) ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(YOUR_TAB_NUMBER));
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) layout.getLayoutParams();
layoutParams.weight = YOUR_WEIGHT; // e.g. 0.5f
layout.setLayoutParams(layoutParams);

希望有帮助!