diff --git a/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java b/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java index c6ce814..538d7b6 100644 --- a/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java +++ b/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java @@ -2,6 +2,7 @@ import android.content.Context; import android.content.res.TypedArray; +import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.Gravity; import android.view.View; @@ -198,7 +199,11 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(minHeight, MeasureSpec.EXACTLY)); - mBackgroundRight = getLeft() + mBackground.getMeasuredWidth(); + if (getParent() instanceof ViewPager) { + mBackgroundRight = mBackground.getMeasuredWidth(); + } else { + mBackgroundRight = getLeft() + mBackground.getMeasuredWidth(); + } mBackgroundBottom = getTop() + mBackground.getMeasuredHeight(); mScrollDiff = (float) (mBackground.getMeasuredHeight() - mScrollViewHeight) @@ -277,7 +282,12 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto // Log.d(TAG, "Layout Scroll Y: " + scrollYCenterOffset + // " ScrollDiff: " + mScrollDiff // + " Background Offset:" + offset); - mBackground.layout(getLeft(), offset, mBackgroundRight, offset + mBackgroundBottom); + if (getParent() instanceof ViewPager) { + mBackground.layout(0, offset, mBackgroundRight, offset + mBackgroundBottom); + } else { + mBackground.layout(getLeft(), offset, mBackgroundRight, offset + mBackgroundBottom); + } + } }