From 9bfe2b2646f3849f5463c63876c184e820a7f03b Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Thu, 2 Jun 2011 16:41:34 -0700 Subject: Fixing bug with layout of PagedViewCellLayoutChildren Change-Id: I3fa34ad500632c4b257973aca9be0cb1bda5884a --- src/com/android/launcher2/PagedViewCellLayout.java | 19 ++++++------------- .../launcher2/PagedViewCellLayoutChildren.java | 15 +++++++++------ 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/com/android/launcher2/PagedViewCellLayout.java b/src/com/android/launcher2/PagedViewCellLayout.java index 0ae7a597c..901ac2680 100644 --- a/src/com/android/launcher2/PagedViewCellLayout.java +++ b/src/com/android/launcher2/PagedViewCellLayout.java @@ -211,8 +211,6 @@ public class PagedViewCellLayout extends ViewGroup implements Page { } protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - // TODO: currently ignoring padding - int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec); int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec); @@ -255,10 +253,8 @@ public class PagedViewCellLayout extends ViewGroup implements Page { widthGap = heightGap = minGap; } - int newWidth = mPaddingLeft + mPaddingRight + (mCellCountX * cellWidth) + - ((mCellCountX - 1) * widthGap); - int newHeight = mPaddingTop + mPaddingBottom + (mCellCountY * cellHeight) + - ((mCellCountY - 1) * heightGap); + int newWidth = (mCellCountX * cellWidth) + ((mCellCountX - 1) * widthGap); + int newHeight = (mCellCountY * cellHeight) + ((mCellCountY - 1) * heightGap); final int count = getChildCount(); for (int i = 0; i < count; i++) { @@ -270,7 +266,8 @@ public class PagedViewCellLayout extends ViewGroup implements Page { child.measure(childWidthMeasureSpec, childheightMeasureSpec); } - setMeasuredDimension(newWidth, newHeight); + setMeasuredDimension(newWidth + mPaddingLeft + mPaddingRight, + newHeight + mPaddingTop + mPaddingBottom); } int getContentWidth() { @@ -304,12 +301,8 @@ public class PagedViewCellLayout extends ViewGroup implements Page { int count = getChildCount(); for (int i = 0; i < count; i++) { View child = getChildAt(i); - if (LauncherApplication.isScreenLarge()) { - child.layout(0, 0, r - l, b - t); - } else { - child.layout(mPaddingLeft, mPaddingTop, getMeasuredWidth() - mPaddingRight, - getMeasuredHeight() - mPaddingBottom); - } + child.layout(mPaddingLeft, mPaddingTop, + r - l - mPaddingRight, b - t - mPaddingBottom); } } diff --git a/src/com/android/launcher2/PagedViewCellLayoutChildren.java b/src/com/android/launcher2/PagedViewCellLayoutChildren.java index 6333f7f2e..1afdd03cf 100644 --- a/src/com/android/launcher2/PagedViewCellLayoutChildren.java +++ b/src/com/android/launcher2/PagedViewCellLayoutChildren.java @@ -92,8 +92,8 @@ public class PagedViewCellLayoutChildren extends ViewGroup { PagedViewCellLayout.LayoutParams lp = (PagedViewCellLayout.LayoutParams) child.getLayoutParams(); lp.setup(mCellWidth, mCellHeight, mWidthGap, mHeightGap, - ((ViewGroup)getParent()).getPaddingLeft(), - ((ViewGroup)getParent()).getPaddingTop()); + getPaddingLeft(), + getPaddingTop()); int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY); @@ -111,18 +111,21 @@ public class PagedViewCellLayoutChildren extends ViewGroup { int count = getChildCount(); int offsetX = 0; - if (mCenterContent) { + if (mCenterContent && count > 0) { // determine the max width of all the rows and center accordingly - int maxRowWidth = 0; + int maxRowX = 0; + int minRowX = Integer.MAX_VALUE; for (int i = 0; i < count; i++) { View child = getChildAt(i); if (child.getVisibility() != GONE) { PagedViewCellLayout.LayoutParams lp = (PagedViewCellLayout.LayoutParams) child.getLayoutParams(); - maxRowWidth = Math.max(maxRowWidth, lp.x + lp.width); + minRowX = Math.min(minRowX, lp.x); + maxRowX = Math.max(maxRowX, lp.x + lp.width); } } - offsetX = (getMeasuredWidth() / 2) - (maxRowWidth / 2); + int maxRowWidth = maxRowX - minRowX; + offsetX = (getMeasuredWidth() - maxRowWidth) / 2; } for (int i = 0; i < count; i++) { -- cgit v1.2.3