背景
查看官方文档,发现Tablayout的API太少,基本上满足不了现在市场各种奇葩的需求,所以就必须自定义布局了╮(╯▽╰)╭!
过程
废话不多说先上效果图:
- 首先是准备工作
1、MainActivity布局,就一组黄金搭档Tablayout+ViewPager,中间View只是一条分割线:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="0dp"
android:layout_height="40dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:tabBackground="@android:color/transparent"
app:tabIndicatorHeight="0dp"
app:tabMode="scrollable" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
app:layout_constraintLeft_toLeftO