am 2478480a: Fixing bug with layout of PagedViewCellLayoutChildren
* commit '2478480a9724804fd363dfa99c42ddfba4c46acc': Fixing bug with layout of PagedViewCellLayoutChildren
This commit is contained in:
commit
c9fa2b7668
2 files changed
+15
-14
No files matched your search
@@ -189,8 +189,6 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
// TODO: currently ignoring padding
|
|
||||||
|
|
||||||
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
|
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||||
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
|
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
|
|
||||||
@@ -233,10 +231,8 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
|
|||||||
widthGap = heightGap = minGap;
|
widthGap = heightGap = minGap;
|
||||||
}
|
}
|
||||||
|
|
||||||
int newWidth = mPaddingLeft + mPaddingRight + (mCellCountX * cellWidth) +
|
int newWidth = (mCellCountX * cellWidth) + ((mCellCountX - 1) * widthGap);
|
||||||
((mCellCountX - 1) * widthGap);
|
int newHeight = (mCellCountY * cellHeight) + ((mCellCountY - 1) * heightGap);
|
||||||
int newHeight = mPaddingTop + mPaddingBottom + (mCellCountY * cellHeight) +
|
|
||||||
((mCellCountY - 1) * heightGap);
|
|
||||||
|
|
||||||
final int count = getChildCount();
|
final int count = getChildCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
@@ -248,7 +244,8 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
|
|||||||
child.measure(childWidthMeasureSpec, childheightMeasureSpec);
|
child.measure(childWidthMeasureSpec, childheightMeasureSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
setMeasuredDimension(newWidth, newHeight);
|
setMeasuredDimension(newWidth + mPaddingLeft + mPaddingRight,
|
||||||
|
newHeight + mPaddingTop + mPaddingBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getContentWidth() {
|
int getContentWidth() {
|
||||||
@@ -278,7 +275,8 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
|
|||||||
int count = getChildCount();
|
int count = getChildCount();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
View child = getChildAt(i);
|
View child = getChildAt(i);
|
||||||
child.layout(0, 0, r - l, b - t);
|
child.layout(mPaddingLeft, mPaddingTop,
|
||||||
|
r - l - mPaddingRight, b - t - mPaddingBottom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ public class PagedViewCellLayoutChildren extends ViewGroup {
|
|||||||
PagedViewCellLayout.LayoutParams lp =
|
PagedViewCellLayout.LayoutParams lp =
|
||||||
(PagedViewCellLayout.LayoutParams) child.getLayoutParams();
|
(PagedViewCellLayout.LayoutParams) child.getLayoutParams();
|
||||||
lp.setup(mCellWidth, mCellHeight, mWidthGap, mHeightGap,
|
lp.setup(mCellWidth, mCellHeight, mWidthGap, mHeightGap,
|
||||||
((ViewGroup)getParent()).getPaddingLeft(),
|
getPaddingLeft(),
|
||||||
((ViewGroup)getParent()).getPaddingTop());
|
getPaddingTop());
|
||||||
|
|
||||||
int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width,
|
int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width,
|
||||||
MeasureSpec.EXACTLY);
|
MeasureSpec.EXACTLY);
|
||||||
@@ -111,18 +111,21 @@ public class PagedViewCellLayoutChildren extends ViewGroup {
|
|||||||
int count = getChildCount();
|
int count = getChildCount();
|
||||||
|
|
||||||
int offsetX = 0;
|
int offsetX = 0;
|
||||||
if (mCenterContent) {
|
if (mCenterContent && count > 0) {
|
||||||
// determine the max width of all the rows and center accordingly
|
// 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++) {
|
for (int i = 0; i < count; i++) {
|
||||||
View child = getChildAt(i);
|
View child = getChildAt(i);
|
||||||
if (child.getVisibility() != GONE) {
|
if (child.getVisibility() != GONE) {
|
||||||
PagedViewCellLayout.LayoutParams lp =
|
PagedViewCellLayout.LayoutParams lp =
|
||||||
(PagedViewCellLayout.LayoutParams) child.getLayoutParams();
|
(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++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
|||||||
Reference in new issue
Block a user