一:添加design依赖
使用TabLayout需要添加design依赖:
implementation 'com.android.support:design:27.1.1'
二:创建Fragment
创建三个Fragment:Fragment1、Fragment2、Fragment3,分别导入页面布局fragment1、fragment2、fragment3:
public class Fragment1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view = inflater.inflate(R.layout.fragment1,container,false);
return view;
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_centerInParent="true"