From 575f69ca827d0c2f575978724871156702cc6325 Mon Sep 17 00:00:00 2001 From: caguilar187 Date: Tue, 12 Nov 2013 16:47:18 -0500 Subject: [PATCH] fixing issue when parallax scrollview parent is a viewpager --- .../views/ParallaxScrollView.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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); + } + } }