diff --git a/labels/src/main/java/com/donkingliang/labels/LabelsView.java b/labels/src/main/java/com/donkingliang/labels/LabelsView.java index d0aa9f6..a61c9cc 100644 --- a/labels/src/main/java/com/donkingliang/labels/LabelsView.java +++ b/labels/src/main/java/com/donkingliang/labels/LabelsView.java @@ -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; } /** @@ -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) { @@ -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; + } + /** * 设置行间隔 */ @@ -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; - } - /** * 设置标签的点击监听 *