TabLayout指示器的长短反射修改
来源:互联网 发布:linux 精确时间 编辑:程序博客网 时间:2024/05/11 15:05
取出所有tab其中最长的文本设置指示器宽度的长短
/** 设置tablayout指示器的长短 * * @param tab */ public static void showTabTextAdapteIndicator(final TabLayout tab) { tab.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { tab.getViewTreeObserver().removeOnGlobalLayoutListener(this); Class<?> tabLayout = tab.getClass(); Field tabStrip = null; try { tabStrip = tabLayout.getDeclaredField("mTabStrip"); } catch (NoSuchFieldException e) { e.printStackTrace(); } tabStrip.setAccessible(true); LinearLayout ll_tab = null; try { ll_tab = (LinearLayout) tabStrip.get(tab); } catch (IllegalAccessException e) { e.printStackTrace(); } int maxLen = 0; int maxTextSize = 0; int tabCount = ll_tab.getChildCount(); for (int i = 0; i < tabCount; i++) { View child = ll_tab.getChildAt(i); child.setPadding(0, 0, 0, 0); if (child instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) child; for (int j = 0; j < ll_tab.getChildCount(); j++) { if (viewGroup.getChildAt(j) instanceof TextView) { TextView tabTextView = (TextView) viewGroup.getChildAt(j); int length = tabTextView.getText().length(); maxTextSize = (int) tabTextView.getTextSize() > maxTextSize ? (int) tabTextView.getTextSize() : maxTextSize; maxLen = length > maxLen ? length : maxLen; } } } int margin = (tab.getWidth() / tabCount - (maxTextSize + UiUtils.dp2px(2)) * maxLen) / 2 - UiUtils.dp2px(2); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1); params.leftMargin = margin; params.rightMargin = margin; child.setLayoutParams(params); child.invalidate(); } } }); }
1 0
- TabLayout指示器的长短反射修改
- 修改TabLayout指示器的长度
- 修改TabLayout底部导航条Indicator的长短
- 通过修改指示器的间距来改变TabLayout指示器的宽度
- TabLayout的指示器宽度问题
- TabLayout设置指示器的宽度
- TabLayout实现ViewPager指示器
- Android TabLayout && 个性指示器
- TabLayout设置指示器长度
- Android--使用反射修改TabLayout下划线宽度
- 实现一个简单的类似 TabLayout 的顶部指示器
- TabLayout的学习以及BUG,Viewpager的指示器
- android.support.design.widget.TabLayout设置指示器的宽度
- Fragment + TabLayout (页签指示器)
- 史上最巧妙自定义tablayout指示器
- TabLayout 修改字体的方法
- 在写Tablayout时候,发现不能设置下划线的长度,使用反射的方式,修改了长度
- 可自定义图片指示器并支持自定义Tab宽度的TabLayout
- Cloudera Manager安装主机节点选不中
- Altium Designer PCB布线之差分对手动设置方法
- Android EventBus 3.0.0 使用总结
- 欢迎使用CSDN-markdown编辑器
- Html表单和表格例子
- TabLayout指示器的长短反射修改
- AVA招聘
- zuul入门
- 【OpenCV3图像处理】颜色空间转换(二)转换函数 cvtColor()
- 数据库存储过程的调用
- Java基础知识总结(逆天经典)
- java web 文件下载
- GMS应用首次登陆闪退,第二次正常
- 数据库的hash索引