ViewPager2与TabLayout
展示效果


说明:项目必须运行在Androidx环境下使用
依赖
implementation ‘androidx.viewpager2:viewpager2:1.0.0-alpha01’
//tablayout
implementation ‘com.google.android.material:material:1.2.0-alpha01’
一.Activity布局
<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=".MainActivity"
android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tablayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/v2"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.viewpager2.widget.ViewPager2>
</Line

本文详细介绍如何在Androidx环境下使用ViewPager2与TabLayout实现流畅的页面切换效果。包括Activity布局配置、代码实现、自定义适配器及Fragment,帮助开发者快速上手。

7651

被折叠的 条评论
为什么被折叠?



