Skip to content

Commit

Permalink
[Fix] There is some spacing between the boxes when 'boxMargin' is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaosLeung committed Jun 21, 2017
1 parent bf259d7 commit d894c84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion pinview/src/main/java/com/chaos/view/PinView.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
} else {
float boxesWidth = (mPinBoxCount - 1) * mPinBoxMargin + mPinBoxCount * boxHeight;
width = Math.round(boxesWidth + getPaddingRight() + getPaddingLeft());
if (mPinBoxMargin == 0) {
width -= 2 * (mPinBoxCount - 1) * mBorderWidth;
}
}

if (heightMode == MeasureSpec.EXACTLY) {
Expand Down Expand Up @@ -366,8 +369,13 @@ private void updateRoundRectPath(RectF rectF, float rx, float ry,

private void updateBoxRectF(int i) {
float startX = (getWidth() - (mPinBoxCount - 1) * mPinBoxMargin - mPinBoxCount * mPinBoxHeight) / 2;

if (mPinBoxMargin == 0) {
startX += (mPinBoxCount - 1) * mBorderWidth;
}
float left = startX + mPinBoxHeight * i + mPinBoxMargin * i + mBorderWidth;
if (mPinBoxMargin == 0 && i > 0) {
left = left - 2 * mBorderWidth * i;
}
float right = left + mPinBoxHeight - 2 * mBorderWidth;
float top = mBorderWidth + getPaddingTop();
float bottom = top + mPinBoxHeight - 2 * mBorderWidth;
Expand Down
2 changes: 1 addition & 1 deletion simple/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
app:borderWidth="2dp"
app:boxCount="5"
app:boxHeight="48dp"
app:boxMargin="4dp"
app:boxMargin="0dp"
app:boxRadius="4dp" />

<com.chaos.view.PinView
Expand Down

0 comments on commit d894c84

Please sign in to comment.