使用心得,勿喷;
1、添加资源:
/** * FlycoTabLayout(TabLayout库) */ implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
2、文件布局:
<com.flyco.tablayout.SlidingTabLayout android:id="@+id/smart_table" android:layout_width="match_parent" android:layout_height="@dimen/base40dp" app:tl_divider_color="@android:color/transparent" app:tl_divider_width="0dp" app:tl_indicator_color="@color/colorAccent" app:tl_indicator_corner_radius="@dimen/base5dp" app:tl_indicator_height="@dimen/base4dp" app:tl_indicator_width="@dimen/base25dp" app:tl_tab_padding="@dimen/base15dp" app:tl_tab_space_equal="true" app:tl_textBold="BOTH" app:tl_textSelectColor="@color/colorText" app:tl_textUnselectColor="@color/colorText" app:tl_textsize="@dimen/base13sp" app:tl_underline_color="@color/colorLine" app:tl_underline_height="1px" /> <androidx.viewpager.widget.ViewPager android:id="@+id/smart_pager" android:layout_width="match_parent" android:layout_height="match_parent" />
3、java代码:
smart_table.setViewPager(smart_pager, new title["标题一","标题一","标题一","标题一"], (FragmentActivity) mContext, fragments); smart_pager.setOffscreenPageLimit(0);//预加载
完成,代码就是这样,不明白请留言