TabLayout的不同选项卡宽度 [英] Different tab width for TabLayout

查看:170
本文介绍了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);

希望有帮助!

这篇关于TabLayout的不同选项卡宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆