From 0f06561a09b9bf534f7f4878f1d52729aa429b3b Mon Sep 17 00:00:00 2001 From: donmahallem Date: Tue, 21 Jan 2014 18:17:21 +0100 Subject: [PATCH 1/3] Earlier Content Width if set to fill/match-parent was ignored It checked only the topmost child which if wasnt filling the screen making the whole scrollview width very small. --- .../views/ParallaxScrollView.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java b/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java index c6ce814..2b273f6 100644 --- a/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java +++ b/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java @@ -178,10 +178,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) if (mScrollView != null) { - measureChild(mScrollView, MeasureSpec.makeMeasureSpec( - MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST), - MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(heightMeasureSpec), - MeasureSpec.AT_MOST)); + measureChildren(widthMeasureSpec, heightMeasureSpec); mScrollContentHeight = mScrollView.getChildAt(0).getMeasuredHeight(); mScrollViewHeight = mScrollView.getMeasuredHeight(); @@ -218,9 +215,9 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto { final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mScrollView .getLayoutParams(); - - final int width = mScrollView.getMeasuredWidth(); - final int height = mScrollView.getMeasuredHeight(); + + final int width = (lp.width==LayoutParams.MATCH_PARENT?this.getWidth():mScrollView.getMeasuredWidth()); + final int height = (lp.height==LayoutParams.MATCH_PARENT?this.getHeight():mScrollView.getMeasuredHeight()); int childLeft; int childTop; @@ -265,14 +262,13 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto default: childTop = parentTop + lp.topMargin; } - mScrollView.layout(childLeft, childTop, childLeft + width, childTop + height); } if (mBackground != null) { - final int scrollYCenterOffset = -mScrollView.getScrollY(); + final int scrollYCenterOffset = mScrollView.getScrollY(); final int offset = (int) (scrollYCenterOffset * mScrollDiff); // Log.d(TAG, "Layout Scroll Y: " + scrollYCenterOffset + // " ScrollDiff: " + mScrollDiff From c8216e2abe57d503ec59c4d3798c01aa252474b9 Mon Sep 17 00:00:00 2001 From: donmahallem Date: Tue, 21 Jan 2014 18:24:03 +0100 Subject: [PATCH 2/3] Added FILL_PARENT for older layouts --- .../parallaxscrollview/views/ParallaxScrollView.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java b/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java index 2b273f6..41d4a99 100644 --- a/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java +++ b/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java @@ -3,6 +3,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; +import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; @@ -216,8 +217,10 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto final FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mScrollView .getLayoutParams(); - final int width = (lp.width==LayoutParams.MATCH_PARENT?this.getWidth():mScrollView.getMeasuredWidth()); - final int height = (lp.height==LayoutParams.MATCH_PARENT?this.getHeight():mScrollView.getMeasuredHeight()); + @SuppressWarnings("deprecation") + final int width = (lp.width==LayoutParams.MATCH_PARENT||lp.width==LayoutParams.FILL_PARENT)?this.getWidth():mScrollView.getMeasuredWidth(); + @SuppressWarnings("deprecation") + final int height = (lp.height==LayoutParams.MATCH_PARENT||lp.height==LayoutParams.FILL_PARENT)?this.getHeight():mScrollView.getMeasuredHeight(); int childLeft; int childTop; @@ -262,6 +265,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto default: childTop = parentTop + lp.topMargin; } + Log.d("Paralax","l: "+childLeft+" - w: "+width); mScrollView.layout(childLeft, childTop, childLeft + width, childTop + height); } From 9b06bdebb87f6679a4bd4da260f9f93773dddf79 Mon Sep 17 00:00:00 2001 From: donmahallem Date: Tue, 21 Jan 2014 18:25:28 +0100 Subject: [PATCH 3/3] Removed unused log --- .../jenxsol/parallaxscrollview/views/ParallaxScrollView.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java b/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java index 41d4a99..af2122e 100644 --- a/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java +++ b/library/src/couk/jenxsol/parallaxscrollview/views/ParallaxScrollView.java @@ -3,7 +3,6 @@ import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; -import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; @@ -265,7 +264,6 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto default: childTop = parentTop + lp.topMargin; } - Log.d("Paralax","l: "+childLeft+" - w: "+width); mScrollView.layout(childLeft, childTop, childLeft + width, childTop + height); }