Infinite ViewPager(无限的 ViewPager)
问题描述
这似乎是可能的,但我在弄清楚如何实现一个可以无限分页的 ViewPager 时遇到了一些麻烦.
This seems possible, but I'm having a little trouble figuring out how to implement a ViewPager that can page indefinitely.
我的用例是一次显示一个月的日历,但可以通过分页足够的次数来切换到任何月份.
My use case is for a calendar that shows a month at a time, but would be able to switch to any month by paging enough times.
目前我只是扩展PagerAdapter,并添加了3个自定义MonthViews,如下所示:
Currently I'm just extending PagerAdapter, and 3 custom MonthViews are added like so:
@Override
public Object instantiateItem(View collection, int position) {
final MonthView mv = new MonthView(HistoryMonthActivity.this);
mv.setLayoutParams(new ViewSwitcher.LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.MATCH_PARENT));
mv.setSelectedTime(mTime);
((DirectionalViewPager) collection).addView(mv, 0);
return mv;
}
我想一次只在内存中保留 3 个 MonthView,以便在每个 MonthView 上显示我的数据库中的数据时不会有很大的延迟当用户点击时.因此,每次显示新页面时,我都需要删除一个 MonthView 并添加一个 MonthView.如果有人对相同的功能有更好的想法,我很想听听!
I would like to keep only 3 MonthViews in memory at a time, so that there isn't a huge delay in displaying data from my database on each MonthView when the user is tabbing. So every time a new page is shown, I will need to remove one MonthView and add one MonthView. If anyone has a better idea for the same functionality , I'd love to hear it!
我正在考虑尝试使用 FragmentStatePagerAdapter.
I'm thinking of trying to use a FragmentStatePagerAdapter.
推荐答案
我能够在我的 MonthView 和 PagerAdapter 中使用一点魔法来实现这个OnPageChangeListener,以及编辑ViewPager本身的源代码.如果有人对我如何实现它感兴趣,查看源代码或针对特定问题发表评论.
I was able to implement this using a little magic in my MonthViews, my PagerAdapter's OnPageChangeListener, as well as with editing the source code of ViewPager itself. If anyone is interested in how I achieved it, check out the source code or comment with a specific question.
这篇关于无限的 ViewPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无限的 ViewPager
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
