Skip to content

Commit

Permalink
完善合并的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
teach committed Oct 9, 2020
1 parent ab03d70 commit 3a054a1
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions labels/src/main/java/com/donkingliang/labels/LabelsView.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ private void measureSingleLine(int widthMeasureSpec, int heightMeasureSpec) {
}
setMeasuredDimension(measureSize(widthMeasureSpec, contentWidth + getPaddingLeft() + getPaddingRight()),
measureSize(heightMeasureSpec, maxItemHeight + getPaddingTop() + getPaddingBottom()));
lines = 1;

// 如果count等于0,没有标签,则lines为0
lines = count > 0 ? 1 : 0;
}

/**
Expand Down Expand Up @@ -282,12 +284,14 @@ private void measureMultiLine(int widthMeasureSpec, int heightMeasureSpec) {
}
}
}
this.lines = lineCount;
contentHeight += maxItemHeight;
maxLineWidth = Math.max(maxLineWidth, lineWidth);

setMeasuredDimension(measureSize(widthMeasureSpec, maxLineWidth + getPaddingLeft() + getPaddingRight()),
measureSize(heightMeasureSpec, contentHeight + getPaddingTop() + getPaddingBottom()));

// 如果count等于0,没有标签,则lines为0
lines = count > 0 ? lineCount : 0;
}

private int measureSize(int measureSpec, int size) {
Expand Down Expand Up @@ -939,6 +943,27 @@ public int getLabelGravity() {
return mLabelGravity;
}

/**
* 设置标签字体是否为粗体
*
* @param isBold
*/
public void setTextBold(boolean isBold) {
if (this.isTextBold != isBold) {
this.isTextBold = isBold;
int count = getChildCount();
for (int i = 0; i < count; i++) {
TextView label = (TextView) getChildAt(i);
label.getPaint().setFakeBoldText(isTextBold);
label.invalidate();
}
}
}

public boolean isTextBold() {
return isTextBold;
}

/**
* 设置行间隔
*/
Expand Down Expand Up @@ -1070,26 +1095,20 @@ public void setSingleLine(boolean isSingleLine) {
}
}

public void setTextBold(boolean isBold) {
if (this.isTextBold != isBold) {
this.isTextBold = isBold;
requestLayout();
}
public boolean isSingleLine() {
return isSingleLine;
}

/**
* 需要在该View的layout完成之后调用,一般是使用view.post(Runable task)来获取
* 比如设置了新的labels之后需要获取新的lines就可以这样
*
* @return
*/
public int getLines() {
return this.lines;
}

public boolean isSingleLine() {
return isSingleLine;
}

/**
* 设置标签的点击监听
*
Expand Down

0 comments on commit 3a054a1

Please sign in to comment.