Skip to content

Commit

Permalink
Fix: add tag dynamically(support max lines version) flickered
Browse files Browse the repository at this point in the history
  • Loading branch information
whilu committed Jun 13, 2016
1 parent 1c70dc2 commit e21218b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Now, you have successfully created some TagViews. The following will show some m
| container_enable_drag | boolean | Can drag TagView(default false)
| container_drag_sensitivity | float | The sensitive of the ViewDragHelper(default 1.0f, normal)
| container_gravity | enum | The TagContainerLayout [gravity](#gravity)
| container_max_lines | integer | The max lines for TagContainerLayout(default 0, auto increase)
| tag_border_width | dimension | TagView Border width(default 0.5dp)
| tag_corner_radius | dimension | TagView Border radius(default 15.0dp)
| tag_horizontal_padding | dimension | Horizontal padding for TagView, include left and right padding(left and right padding are equal, default 20px)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class TagContainerLayout extends ViewGroup {
/** The container layout gravity(default left)*/
private int mGravity = Gravity.LEFT;

/** The max line count of container */
/** The max line count of TagContainerLayout */
private int mMaxLines = 0;

/** The max length for TagView(default max length 23)*/
Expand Down Expand Up @@ -299,14 +299,6 @@ protected void onDraw(Canvas canvas) {
mPaint.setStrokeWidth(mBorderWidth);
mPaint.setColor(mBorderColor);
canvas.drawRoundRect(mRectF, mBorderRadius, mBorderRadius, mPaint);

if(mMaxLines <=0)
return;

int lineCount = getChildLines(mChildViews.size());
if(lineCount > mMaxLines) {
removeTag(mChildViews.size()-1);
}
}

@Override
Expand Down Expand Up @@ -342,7 +334,8 @@ private int getChildLines(int childCount){
curLineW = dis;
}
}
return lines;

return mMaxLines <= 0 ? lines : mMaxLines;
}

private int[] onUpdateColorFactory(){
Expand Down Expand Up @@ -791,14 +784,22 @@ public void setSensitivity(float sensitivity) {
}

/**
* Set max line count for TagContainer
* Set max line count for TagContainerLayout
* @param maxLines max line count
*/
public void setMaxLines(int maxLines) {
mMaxLines = maxLines;
postInvalidate();
}

/**
* Get TagContainerLayout's max lines
* @return maxLines
*/
public int getMaxLines(){
return mMaxLines;
}

/**
* Set the TagView text max length(must greater or equal to 3).
* @param maxLength
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/java/co/lujun/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ public void onClick(View v) {
}
});

mTagContainerLayout1.setMaxLines(1);
// mTagContainerLayout1.setMaxLines(1);
}
}

0 comments on commit e21218b

Please sign in to comment.