TabLayout 的不同选项卡宽度

问题描述:

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

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.

需要降低对应tab的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);

希望有帮助!