XTabLayout

Project Url: JasonGaoH/XTabLayout
Introduction: TabLayout 的增强版,添加 TabLayout Indicator 宽度的自定义,添加仿微博,即刻等导航条的动画效果。
More: Author   ReportBugs   
Tags:

背景

XTabLayout 主要是基于原生 TabLayout 的改造,最早的需求是想可以手动调整 TabLayout 的下划线宽度,由于项目中 TabLayout 和 ViewPager 这样的使用方式很多,所以不想改动太多现有代码,在对比了各种改动 TabLayout 的下划线宽度之后,发现这种基于系统 TabLayout 改造的 XTabLayout 这种实现更好,另外可定制性也更高。

比较

各种改动 优势 局限
系统 TabLayout 无需代码改动 不够灵活,各种属性不能定制
基于系统 TabLayout 反射一 改动小 不够灵活,容易有兼容问题,TabLayout 一些属性会失效,比如 tabMode 设置 scrollable 会失效
基于系统 TabLayout 反射二 改动小 不够灵活,容易有兼容问题,会压缩 TabLayout 的 Tab 左右 padding,这样 tab 的可点击区域会变小
XTabLayout 灵活,定制性高 需要修改不少 TabLayout 的逻辑

可以看下面的截图效果比较:

GIF 展示:

另外

在支持用 x_tabIndicatorWidth 属性来动态设置下划线高度的同时,还增加了以下新功能:

  1. 添加 x_tabIndicatorAnimation 来控制是否支持类似微博的导航条动效,默认 false 不支持
  2. 添加 x_tabIndicatorRoundRect 来控制 Indicator 下划线的圆角效果,默认 false 没有圆角
  3. 支持在 Tab 上加入红点和红点数字

详情请见博客链接:关于 TabLayout 的 indicator 宽度的一次探索

关于

博客:https://jasongaoh.github.io

邮箱:jasongaohui@gmail.com

License

Copyright 2018 JasonGaoH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools