实现,县级、市级、省级三个fragment切换
1.排行榜的布局文件 activity_region_list.xml
<?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="match_parent"
tools:context=".RegionListActivity"
android:background="@color/weakgreen"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_gravity="center"
android:background="@color/weakgreen">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="@color/green">
<TextView
android:id="@+id/text_region_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="战区排行榜"
android:textColor="@color/white"
android:textSize="30sp"
android:textStyle="bold"
android:layout_gravity="bottom|center"
android:layout_marginBottom="5dp"
android:layout_centerInParent="true"
/>
</androidx.appcompat.widget.Toolbar>
</RelativeLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tl_tab_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabIndicatorFullWidth="false"
app:tabMode="fixed">
</com.google.android.material.tabs.TabLayout>
<!-- app:tabBackground="@color/green"-->
<androidx.viewpager.widget.ViewPager
android:id="@+id/vpager_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.viewpager.widget.ViewPager>
</LinearLayout>
2.排行榜的java代码 RegionListActivity.java
public class RegionListActivity extends AppCompatActivity {
TabLayout mTablayout;
ViewPager mViewPager;
private TabLayout.Tab tab_county,tab_city,tab_province;
private String phone ="";
private String province,city,county;
private List<RegionUser> regionUsers = new ArrayList<>();
@Override
protected