Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pager clipped when having a large number of pages #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import android.os.Build;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
Expand Down Expand Up @@ -46,6 +48,7 @@ public class PaperOnboardingEngine implements PaperOnboardingEngineDefaults {

private final RelativeLayout mContentRootLayout;
private final LinearLayout mContentCenteredContainer;
private final HorizontalScrollView mPagerLayoutContainer;

// application context
private final Context mAppContext;
Expand Down Expand Up @@ -88,6 +91,26 @@ public PaperOnboardingEngine(View rootLayout, ArrayList<PaperOnboardingPage> con
mContentRootLayout = (RelativeLayout) mRootLayout.getChildAt(1);
mContentCenteredContainer = (LinearLayout) mContentRootLayout.getChildAt(0);

/* Disable scrolling on scroll view but enable swipe */
mPagerLayoutContainer = rootLayout.findViewById(R.id.onboardingPagerLayoutContainer);
mPagerLayoutContainer.setOnTouchListener(new OnSwipeListener(mAppContext) {
@Override
public boolean onTouch(View v, MotionEvent event) {
super.onTouch(v, event);
return true;
}

@Override
public void onSwipeRight() {
toggleContent(true);
}

@Override
public void onSwipeLeft() {
toggleContent(false);
}
});

this.dpToPixelsScaleFactor = this.mAppContext.getResources().getDisplayMetrics().density;

initializeStartingState();
Expand Down Expand Up @@ -144,7 +167,7 @@ protected int calculateNewPagerPosition(int newActiveElement) {
int pagerActiveElemCenterPosX = mPagerElementActiveSize / 2
+ newActiveElement * mPagerElementLeftMargin
+ (newActiveElement - 1) * (mPagerElementNormalSize + mPagerElementRightMargin);
return mRootLayout.getWidth() / 2 - pagerActiveElemCenterPosX;
return mPagerLayoutContainer.getWidth() / 2 - pagerActiveElemCenterPosX;
}

/**
Expand Down
29 changes: 20 additions & 9 deletions paper-onboarding/src/main/res/layout/onboarding_main_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,27 @@
</RelativeLayout>

<!-- PAGER ICONS CONTAINER -->
<LinearLayout
android:id="@+id/onboardingPagerIconsContainer"
android:layout_width="wrap_content"
android:layout_height="40dp"
<HorizontalScrollView
android:id="@+id/onboardingPagerLayoutContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="25dp"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal" />
android:scrollbars="none"
android:layout_marginEnd="54dp"
android:layout_marginRight="54dp"
android:layout_marginStart="54dp"
android:layout_marginLeft="54dp">
<LinearLayout
android:id="@+id/onboardingPagerIconsContainer"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="25dp"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal" />
</HorizontalScrollView>



</RelativeLayout>