ViewPagerFragment多页面滑动框架

多个页面的滑动切换用得比较多的就是 ViewPager 配 Fragment,配合 RecyclerView 还能搞出内容丰富的滑块式界面。这个 ViewPagerFragment 的组合,用起来还挺顺手的,页面切换流畅,维护也方便,适合那种需要多页面展示的场景,比如商品分类、引导页、或者新闻页签啥的。

ViewPager 的事你肯定听说过,它其实就是个容器,能让你左右滑动切页面。每个页面通常用一个Fragment来承载。你只需要写个适配器,比如FragmentPagerAdapter或者FragmentStatePagerAdapter,把 Fragment 传进去就完事了。

适配器里主要实现getItemCount()instantiateItem()destroyItem()这几个方法,负责创建和销毁页面。你在Activity布局里放个 ViewPager,代码里绑上适配器就能跑。

要是每个 Fragment 里内容比较多,还能用RecyclerView来展示列表数据。它比以前的 ListView 强多了,布局灵活、性能也好。你自己写个RecyclerViewAdapter,实现onCreateViewHolder()onBindViewHolder()getItemCount(),数据一绑,展示就出来了。

有些场景你还得监听滑动,比如切换页面时改下导航条状态,用OnPageChangeListener就行。如果数据变了,记得notifyDataSetChanged()一下,刷新一下页面,不然用户看到的还停留在旧数据。

,这套组合拳(ViewPager+Fragment+RecyclerView)在 Android 项目里还挺万能的,适用面广。想扩展也容易,比如加个分页加载、加点动画,体验马上就上去了。

如果你正在做那种多 Tab 页面的 App,不妨试试这个组合,用起来还蛮香的~

folder
ViewPagerFragment 预估大小:1436个文件
file
localJarClasspathSnapshot.bin 20KB
file
localClassSetAnalysis.bin 22KB
file
fileSnapshotsToTreeSnapshotsIndex.bin 24KB
file
fileHashes.bin 144KB
file
taskArtifacts.bin 95KB
file
fileSnapshots.bin 2.22MB
file
gradlew.bat 2KB
file
MediaDescriptionCompat.aidl 683B
file
MediaMetadataCompat.aidl 680B
file
ParcelableVolumeInfo.aidl 689B
file
MediaSessionCompat.aidl 787B
file
PlaybackStateCompat.aidl 688B
file
RatingCompat.aidl 673B
file
ResultReceiver.aidl 675B
file
R$style.class 22KB
file
R$styleable.class 23KB
file
R$style.class 22KB
file
R$styleable.class 22KB
file
resources-debug.ap_ 506KB
file
resources-debug-androidTest.ap_ 1KB
zip 文件大小:22.33MB