项目中要求Tab下划线的长度比文字小,网上找了一下解决方法,发现有很多很好的教程,下面记录一下我觉得是比较不错关于解决这个问题的博文
1、博文推荐分享
这里分享几篇不错的文章:
Android自定义Tablayout下划线指示器Indicator:设置宽高、圆角、渐变颜色
关于Android改变TabLayout 下划线(Indicator)宽度实践总结
简单优雅的使用tablayout和viewpager打造导航栏
获取TabLayout的真实宽度,TabLayout的Tab宽度
2、解决平板上Tab不能平方铺满全屏的问题
<android.support.design.widget.TabLayout
android:id="@+id/enhance_tab_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorHeight="0dp"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabGravity="fill"
>
</android.support.design.widget.TabLayout>
一定要设置的核心属性
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabGravity="fill"

网友评论