Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Fix #4, indicator not centered in horizontal mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAfc committed Apr 27, 2017
1 parent 2a6bbf8 commit 5900447
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;

/**
* Created by mikeafc on 15/11/25.
*/
Expand Down Expand Up @@ -127,16 +128,16 @@ protected void onDraw(Canvas canvas) {
if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
longSize = viewPager.getWidth();
shortSize = viewPager.getHeight();
longPaddingBefore = (int) (getItemWidth() + getPaddingLeft() + marginLeft);
longPaddingBefore = getPaddingLeft() + marginLeft;
longPaddingAfter = getPaddingRight() + marginRight;
shortPaddingBefore = (int) (getItemWidth() + getPaddingTop() + marginTop);
shortPaddingBefore = getPaddingTop() + marginTop;
shortPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom;
} else {
longSize = viewPager.getHeight();
shortSize = viewPager.getWidth();
longPaddingBefore = (int) (getItemWidth() + getPaddingTop() + marginTop);
longPaddingBefore = getPaddingTop() + marginTop;
longPaddingAfter = (int) paintStroke.getStrokeWidth() + getPaddingBottom() + marginBottom;
shortPaddingBefore = (int) (getItemWidth() + getPaddingLeft() + marginLeft);
shortPaddingBefore = getPaddingLeft() + marginLeft;
shortPaddingAfter = getPaddingRight() + marginRight;
}

Expand All @@ -149,7 +150,7 @@ protected void onDraw(Canvas canvas) {
float shortOffset = shortPaddingBefore;
float longOffset = longPaddingBefore;

final float indicatorLength = count * itemWidth * widthRatio + (count - 1) * indicatorPadding;
final float indicatorLength = (count - 1) * (itemWidth * widthRatio + indicatorPadding);

final int horizontalGravityMask = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
final int verticalGravityMask = gravity & Gravity.VERTICAL_GRAVITY_MASK;
Expand All @@ -159,13 +160,14 @@ protected void onDraw(Canvas canvas) {
break;
case Gravity.RIGHT:
if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
longOffset = longSize - longPaddingAfter - indicatorLength;
longOffset = longSize - longPaddingAfter - indicatorLength - itemWidth;
}
if (orientation == UltraViewPager.Orientation.VERTICAL) {
shortOffset = shortSize - shortPaddingAfter - itemWidth;
}
break;
case Gravity.LEFT:
longOffset += itemWidth;
default:
break;
}
Expand All @@ -183,6 +185,7 @@ protected void onDraw(Canvas canvas) {
}
break;
case Gravity.TOP:
shortOffset += itemWidth;
default:
break;
}
Expand All @@ -202,6 +205,7 @@ protected void onDraw(Canvas canvas) {
//Draw stroked circles
for (int iLoop = 0; iLoop < count; iLoop++) {
float drawLong = longOffset + (iLoop * (itemWidth * widthRatio + indicatorPadding));

if (orientation == UltraViewPager.Orientation.HORIZONTAL) {
dX = drawLong;
dY = shortOffset;
Expand Down Expand Up @@ -387,7 +391,7 @@ public IUltraIndicatorBuilder setMargin(int left, int top, int right, int bottom

@Override
public void build() {
if(indicatorBuildListener != null){
if (indicatorBuildListener != null) {
indicatorBuildListener.build();
}
}
Expand Down

0 comments on commit 5900447

Please sign in to comment.