TabLayout中的Tab.setCustomView左右有空隙,TabLayout下划线间隙设置,下划线长度设置
间隙设置为零
因为当我们引入TabLayout时就已经默认tabPaddingStart为12dp,tabPaddingEnd为12dp.才会导致不能填满的原因,这时我们只需要修改样式或者属性即可。
xmlns:app="http://schemas.android.com/apk/res-auto"
app:tabPaddingStart="0dp" app:tabPaddingEnd="0dp"
间隙大小设置,下划线长度设置
<com.google.android.material.tabs.TabLayoutandroid:layout_below="@+id/topli11"android:id="@+id/activity_tablayoutt"android:layout_width="match_parent"android:layout_height="@dimen/normal_110dp"android:background="@color/white"app:tabBackground="@null"app:tabRippleColor="@null"app:tabIndicatorColor="#4065E0"app:tabIndicatorHeight="@dimen/normal_5dp"app:tabIndicatorFullWidth="false"app:tabPaddingStart="@dimen/normal_70dp"app:tabPaddingEnd="@dimen/normal_70dp"app:tabMaxWidth="@dimen/normal_305dp"/>
<com.google.android.material.tabs.TabLayoutandroid:layout_below="@+id/topli11"android:id="@+id/activity_tablayoutt"android:layout_width="match_parent"android:layout_height="@dimen/normal_110dp"android:background="@color/white"app:tabBackground="@null"app:tabRippleColor="@null"app:tabIndicatorColor="#4065E0"app:tabIndicatorHeight="@dimen/normal_4dp"app:tabMaxWidth="@dimen/normal_180dp" />
方法二——api28以下使用
tabLayout.post(new Runnable() {@Overridepublic void run() {setIndicator(tabLayout);} });
-----------------------------------------------------------------------------
/*** 设置tabLayout下划线的宽*/ public static void setIndicator(TabLayout tabs) {Class<?> tabLayout = tabs.getClass();Field tabStrip = null;try {tabStrip = tabLayout.getDeclaredField("slidingTabIndicator");} catch (NoSuchFieldException e) {e.printStackTrace();}tabStrip.setAccessible(true);LinearLayout llTab = null;try {llTab = (LinearLayout) tabStrip.get(tabs);} catch (IllegalAccessException e) {e.printStackTrace();}//因为我想要的效果是 字多宽线就多宽,所以测量mTextView的宽度for (int i = 0, count = llTab.getChildCount(); i < count; i++) {//获取tabViewView tabView = llTab.getChildAt(i);//拿到tabView的mTextView属性Field mTextViewField = null;try {//获取tabView的textView属性mTextViewField = tabView.getClass().getDeclaredField("textView");} catch (NoSuchFieldException e) {e.printStackTrace();}mTextViewField.setAccessible(true);TextView textView = null;try {textView = (TextView) mTextViewField.get(tabView);} catch (IllegalAccessException e) {e.printStackTrace();}tabView.setPadding(0, 0, 0, 0);//获取textview宽度int textWidth = 0;textWidth = textView.getWidth();if (textWidth == 0) {textView.measure(0, 0);textWidth = textView.getMeasuredWidth();}//获取tabview宽度int tabWidth = 0;tabWidth = tabView.getWidth();if (tabWidth == 0) {tabView.measure(0, 0);tabWidth = tabView.getMeasuredWidth();}//设置下划线margin值LinearLayout.LayoutParams tabViewParams = (LinearLayout.LayoutParams) tabView.getLayoutParams();int margin = (tabWidth - textWidth) / 2;tabViewParams.leftMargin = margin;tabViewParams.rightMargin = margin;tabView.setLayoutParams(tabViewParams);}}
TabLayout中的Tab.setCustomView左右有空隙,TabLayout下划线间隙设置,下划线长度设置相关推荐
- TabLayout+ViewPager实现tab切换
声明: 此文章主要来自:TabLayout+ViewPager轻松搞定Tab栏切换 ,原作者写的很详细.但是为了加深印象,以及对其中的部分现象进行更好的演示,特此重新写一遍. 前言: 在项目开发中很多 ...
- android自定义tab下划线变大,Android开发之设置TabLayout下方下划线的宽度
由于最近项目需要,需要设置tabLayout下方下划线的长度.笔者上网找了半天,也没有找到方法.后来了解到在源码中对tabLayout的下划线进行了设置.并没有方法可以直接设置. 然后,笔者看到了某位 ...
- android开发实现tab,Android 开发之获得Tablayout中子Tab所在的View
最近项目中想做一个新手提示的功能,就是在指定的View上弹出一个类似PopupView的气泡提示框. 效果见下图: Screenshot_20170426-151801_01.png 预想在TabLa ...
- android 展示虚拟键盘,在android TabLayout中显示虚拟键盘
我正在使用TabLayout来显示不同的输入方法.第一个选项卡包含按钮,第四个选项卡应显示此TabLayout中嵌入的标准键盘.这里有截图如何: TabLayout到目前为止工作.我尝试使用Keybo ...
- TabLayout动态添加Tab (动态设置TabMod)
动态添加Tab(自定义tab,包括指示器) 动态设置TabLayout的宽度 做TabLayout的时候tab太少导致不能填充满宽度,设置Fixed模式可以,但是tab增多的时候会挤在一起,导致tab ...
- 如何快速将文本中的tab更换成逗号(图文详解)
不多说,直接上干货! 现有一份数据如下. 下载日志数据并分析 到搜狗实验室下载用户查询日志 1) 介绍 搜索引擎查询日志库设计为包括约1个月(2008年6月)Sogou搜索引擎部分网页查询需求及用户点 ...
- C++读取文本文件中以TAB作为分隔符,且中间字段有为空的情况的方法?
数据文件:testData.txt 内容: 111 222 444 555 思路: getline()将testData.txt中的第一行记录读入到一个string中,然后搜索第n个分隔符进行定位,判 ...
- 转:设置Eclipse中的tab键为4个空格的完整方法
from: https://my.oschina.net/xunxun10/blog/110074 设置Eclipse中的tab键为4个空格的完整方法 收藏 XunXun10 发表于 4年前 阅读 4 ...
- 在VC++中使用Tab Control控件
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 系统环境 ...
最新文章
- python3 collections模块_Python3之collections模块
- python读取excel-python读写Excel
- 【Java网络编程(二)】UDP案例——在线咨询
- 【每日一题】4月7日题目精讲 树
- java期末考试2013及答案_java笔试经典(题及答案)2013.doc
- linux基础磁盘管理,Linux基础入门-文件系统操作与磁盘管理
- sql中 in 、not in 、exists、not exists 用法和差别
- JSON Web Token(缩写 JWT) 目前最流行的跨域认证解决方案
- STM32:UART中的硬件流控RTS与CTS
- 【linux】常用命令之scp命令
- PDFlib TET Crack,文本提取工具包
- pioneer软件VoLTE测试步骤,Pioneer操作说明.docx
- 从实战思路学习前端的设计模式
- 为什么现在微信附近人“没人”了
- 判断正方形和圆形相交
- 云虚拟主机worldpress安装教程
- CTF题库-实验吧(密码学)之综合篇
- 不错的U3D第一人称射击类游戏教程
- JMF环境配置(Eclipse)
- 题解-CTS2019氪金手游