滑动标签栏在App中很常见,以前自己试着实现了一个,使用HorizontalScrollView以及跟ViewPager的,现在有了TabLayout方便了很多,先上效果图,UI略丑,别介意哈~ PS:最下方有源码链接
<script type="math/tex" id="MathJax-Element-1"> </script>
效果图
废话不说,直接上代码!
**
一、添加依赖
implementation 'com.android.support:design:27.0.2'
二、布局文件activity_tablayout.xml
只有一个TabLayout和ViewPager而已
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height=