PagerAdapter start position

前端 未结 9 1100

I\'m using the following example to impliment my viewPager: http://code.google.com/p/viewpagerexample/issues/list

The problem with this example is that I can\'t figure o

相关标签:
9条回答
  • 2021-01-30 08:42

    I'm using 3 fragments and on starting my app, the second (middle) fragment will be shown by default. Just I'm using the onResume function and all works great.

    @Override
    protected void onResume() {
        super.onResume();
        m_viewPager.setCurrentItem(1);
    }
    
    0 讨论(0)
  • 2021-01-30 08:44

    Using viewPager.setCurrentItem(newPosition); shows to the user the transition from the starting page to the newPosition, to prevent that from happening and show the newPosition directly as if it was the starting point, I added false to the second parameter something like this:

    int newPosition = pages.size()-1; // Get last page position
    
    viewPager.setCurrentItem(newPosition, false); // 2nd parameter (false) stands for "smoothScroll"
    
    0 讨论(0)
  • 2021-01-30 08:55

    I've found a way to set it's position, which is done outside of the class:

     awesomePager = (ViewPager) findViewById(R.id.awesomepager);
     awesomePager.setAdapter(awesomeAdapter);
     awesomePager.setCurrentItem(CurrentPosition);
    

    and it can be limited by calculating the amount of items I want to fit in to it

    0 讨论(0)
提交回复
热议问题