سؤال

i'm using RealViewSwitcher I got from this site.

It works perfectly on my code, but I don't have any idea how to set the initial current screen to second or third screen.

the method setCurrentScreen(int) doesn't affect anything and if I change the for loop inside the onLayout() method from for (int i = 0; i < count; i++) {...} into for (int i = 1; i < count; i++){...} It does starts in page two, but you can't go to page one.

Any idea how to start on page two?

هل كانت مفيدة؟

المحلول

The local solution is to add new class method. If you want start on second page - just call snapToScreenFast(2).

public void snapToScreenFast(int whichScreen) {
    if (!mScroller.isFinished())
        return;

    whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));

    mNextScreen = whichScreen;

    final int newX = whichScreen * getWidth();
    final int delta = newX - getScrollX();
    mScroller.startScroll(getScrollX(), 0, delta, 0, 0);
    invalidate();
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top