Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One possibility is setting up the screens like this:</p> <p>C' A B C A'</p> <p>C' looks just like C, but when you scroll to there, it switches you to the real C. A' looks just like A, but when you scroll to there, it switches you to the real A.</p> <p>I would do this by implementing <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html#onPageScrollStateChanged%28int%29">onPageScrollStateChanged</a> like so:</p> <pre><code>@Override public void onPageScrollStateChanged (int state) { if (state == ViewPager.SCROLL_STATE_IDLE) { int curr = viewPager.getCurrentItem(); int lastReal = viewPager.getAdapter().getCount() - 2; if (curr == 0) { viewPager.setCurrentItem(lastReal, false); } else if (curr &gt; lastReal) { viewPager.setCurrentItem(1, false); } } } </code></pre> <p>Note that this calls the alternate form of <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setCurrentItem%28int,%20boolean%29">setCurrentItem</a> and passes <code>false</code> to cause the jump to happen instantly rather than as a smooth scroll.</p> <p>There are two main drawbacks I see to this. Firstly, upon reaching either end the user has to let the scrolling settle before they can go further. Secondly, it means having a second copy of all of the views in your first and last page. Depending on how resource-heavy your screens are, that may rule out this technique as a possible solution.</p> <p>Note also that since the view pager doesn't let clicks go through to underlying controls until after the scrolling has settled, it's probably fine to not set up clicklisteners and the like for the A' and C' fragments.</p> <p><strong>Edit:</strong> Having now implemented this myself, there's another pretty major drawback. When it switches from A' to A or C' to C, the screen flickers for a moment, at least on my current test device.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload