本文介绍了无限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 S在内存中的时间,这样就不是一个巨大的延迟从我的数据库显示,在每个数据 MonthView 当用户按Tab键。因此,一个新的页面显示每一次,我将需要删除一个 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

推荐答案

我能在我的 MonthView s到实现这个用小魔术,我的 PagerAdapter OnPageChangeListener ,以及与编辑的源$ C ​​$ C ViewPager 本身。如果有人有兴趣我是如何做到了这一点,<一个href="http://$c$c.google.com/p/electricsleep/source/browse/trunk/src/com/androsz/electricsleepbeta/app/HistoryMonthActivity.java">check出源$ C ​​$ C 或与特定的问题发表评论。

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 20:05