Skip to content

Commit

Permalink
修复grid布局下的测量问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LRH1993 committed Aug 8, 2017
1 parent adb9dde commit 1494912
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions library/src/main/java/com/example/library/AutoFlowLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,13 @@ private void setGridMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthResult;
//未设置行数 推测行数
if (mRowNumbers == 0) {
mRowNumbers = getChildCount()/mColumnNumbers == 0 ?
mRowNumbers = getChildCount()%mColumnNumbers == 0 ?
getChildCount()/mColumnNumbers : (getChildCount()/mColumnNumbers + 1);
}
int maxChildHeight = 0;
int maxWidth = 0;
int maxHeight = 0;
int maxLineWidth = 0;
//统计最大高度/最大宽度
for (int i = 0; i < mRowNumbers; i++) {
for (int j = 0; j < mColumnNumbers; j++) {
Expand All @@ -192,11 +193,13 @@ private void setGridMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// 得到child的lp
MarginLayoutParams lp = (MarginLayoutParams) child
.getLayoutParams();
maxWidth +=child.getMeasuredWidth()+lp.leftMargin+lp.rightMargin;
maxLineWidth +=child.getMeasuredWidth()+lp.leftMargin+lp.rightMargin;
maxChildHeight = Math.max(maxChildHeight, child.getMeasuredHeight()+lp.topMargin+lp.bottomMargin);
}
}
}
maxWidth = Math.max(maxLineWidth,maxWidth);
maxLineWidth = 0;
maxHeight += maxChildHeight;
maxChildHeight = 0;
}
Expand Down

0 comments on commit 1494912

Please sign in to comment.