android Tablayout+ViewPager实现选项卡滑动效果(战区排行榜)

本文介绍如何使用Tablayout+ViewPager在Android中实现县级、市级、省级三个Fragment的滑动切换效果,详细讲解了activity_region_list.xml布局文件、RegionListActivity.java代码、RegionPagerAdapter适配器以及BaseFragment的懒加载和CountyFragment等关键步骤。
摘要由CSDN通过智能技术生成

实现,县级、市级、省级三个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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值