Skip to content

Commit

Permalink
修复测量的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
teach committed Jan 18, 2019
1 parent 9a81cfd commit f1d19a0
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions labels/src/main/java/com/donkingliang/labels/LabelsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,13 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int lineWidth = 0; //记录行的宽度
int maxLineWidth = 0; //记录最宽的行宽
int maxItemHeight = 0; //记录一行中item高度最大的高度
boolean begin = true; //是否是行的开头
int lineCount = 1;

for (int i = 0; i < count; i++) {
View view = getChildAt(i);
measureChild(view, widthMeasureSpec, heightMeasureSpec);

if (!begin) {
lineWidth += mWordMargin;
} else {
begin = false;
}

if (maxWidth <= lineWidth + view.getMeasuredWidth()) {
if (lineWidth + view.getMeasuredWidth() > maxWidth) {
lineCount++;
if (mMaxLines > 0 && lineCount > mMaxLines) {
break;
Expand All @@ -165,11 +158,27 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
maxItemHeight = 0;
maxLineWidth = Math.max(maxLineWidth, lineWidth);
lineWidth = 0;
begin = true;
}
maxItemHeight = Math.max(maxItemHeight, view.getMeasuredHeight());

lineWidth += view.getMeasuredWidth();
maxItemHeight = Math.max(maxItemHeight, view.getMeasuredHeight());

if (i != count -1) {
if (lineWidth + mWordMargin > maxWidth) {
// 换行
lineCount++;
if (mMaxLines > 0 && lineCount > mMaxLines) {
break;
}
contentHeight += mLineMargin;
contentHeight += maxItemHeight;
maxItemHeight = 0;
maxLineWidth = Math.max(maxLineWidth, lineWidth);
lineWidth = 0;
} else {
lineWidth += mWordMargin;
}
}
}

contentHeight += maxItemHeight;
Expand Down

0 comments on commit f1d19a0

Please sign in to comment.