简单实现了TableLay与ViewPager的简单结合,这里用的是fragment;
效果图如下:
首先,要使用TabLayout必须在AndroidStudio中导入这个依赖库(根据自己编译sdk版本选择)
compile 'com.android.support:design:25.1.0'
主界面布局:注意这里的tablelayout要用android.support.design.widget.TabLayout中的而不是android.widget.TableLayout;另外注意app的命名空间
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/main_tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="#000000"
app:tabIndicatorColor="#FF4081"