Skip to content

Commit

Permalink
Fix: cross set padding bug
Browse files Browse the repository at this point in the history
  • Loading branch information
whilu committed Nov 9, 2016
1 parent 2700c13 commit da1318d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public class TagContainerLayout extends ViewGroup {
/** The cross area width(default 0dp) */
private float mCrossAreaWidth = 0.0f;

/** The padding of the cross area(default 15dp)*/
private float mCrossAreaPadding = 15.0f;
/** The padding of the cross area(default 10dp)*/
private float mCrossAreaPadding = 10.0f;

/** The cross icon color(default black)*/
private int mCrossColor = Color.BLACK;
Expand Down Expand Up @@ -1126,7 +1126,7 @@ public float getCrossAreaPadding() {
}

/**
* Set TagView cross area padding, default 15dp.
* Set TagView cross area padding, default 10dp.
* @param mCrossAreaPadding
*/
public void setCrossAreaPadding(float mCrossAreaPadding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ protected void onDraw(Canvas canvas) {
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(mTextColor);

if (isEnableCross()){
mCrossAreaPadding = mCrossAreaPadding > getHeight() / 2 ? getHeight() / 2 : mCrossAreaPadding;
}

if (mTextDirection == View.TEXT_DIRECTION_RTL){
float tmpX = (isEnableCross() ? getWidth() + getHeight() : getWidth()) / 2 + fontW / 2;
for (char c : mAbstractText.toCharArray()) {
Expand All @@ -216,12 +220,13 @@ protected void onDraw(Canvas canvas) {
if (isEnableCross()){
mCrossLT.set((int)(getWidth() - getHeight() + mCrossAreaPadding),
(int)(mCrossAreaPadding));
Log.d("debugs", "" + mCrossAreaPadding);
mCrossLB.set((int)(getWidth() - getHeight() + mCrossAreaPadding),
(int)(getHeight() - mCrossAreaPadding));
mCrossRT.set((int)(getWidth() - mCrossAreaPadding), (int)(mCrossAreaPadding));
mCrossRB.set((int)(getWidth() - mCrossAreaPadding),
(int)(getHeight() - mCrossAreaPadding));
Log.d("debugs", "getWidth() = " + getWidth() + ", getHeight()=" + getHeight()
+ ", mCrossAreaPadding=" +mCrossAreaPadding + ", mCrossLT.x=" + mCrossLT.x);
}
canvas.drawText(mAbstractText,
(isEnableCross() ? getWidth() - getHeight() : getWidth()) / 2 - fontW / 2,
Expand Down
1 change: 0 additions & 1 deletion sample/src/main/res/layout/content_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
app:tag_theme="pure_teal"
app:vertical_interval="10dp"
app:tag_enable_cross="true"
app:tag_cross_area_padding="25dp"
app:tag_cross_width="40dp"/>

<LinearLayout
Expand Down

0 comments on commit da1318d

Please sign in to comment.