diff --git a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
index ece35cc..e27baca 100644
--- a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
+++ b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java
@@ -156,6 +156,11 @@ public class NumberPicker extends LinearLayout {
*/
private static final int DEFAULT_TEXT_ALIGN = CENTER;
+ /**
+ * The default content alignment.
+ */
+ private static final int DEFAULT_ALIGN = CENTER;
+
/**
* The default color of text.
*/
@@ -630,6 +635,16 @@ private enum DividerType {
*/
private ViewConfiguration mViewConfiguration;
+ /**
+ * The content alignment.
+ */
+ private int mAlign = DEFAULT_ALIGN;
+
+ /**
+ * The padding applied to the content when it's not centered (align is "left" or "right").
+ */
+ private int mSidePadding = 0;
+
/**
* Interface to listen for changes of the current value.
*/
@@ -814,6 +829,9 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
R.styleable.NumberPicker_np_hideWheelUntilFocused, false);
mAccessibilityDescriptionEnabled = attributes.getBoolean(
R.styleable.NumberPicker_np_accessibilityDescriptionEnabled, true);
+ mAlign = attributes.getInt(R.styleable.NumberPicker_np_align, mAlign);
+ mSidePadding = attributes.getDimensionPixelSize(
+ R.styleable.NumberPicker_np_sidePadding, mSidePadding);
// By default LinearLayout that we extend is not drawn. This is
// its draw() method is not called but dispatchDraw() is called
@@ -1767,7 +1785,14 @@ protected void onDraw(Canvas canvas) {
canvas.clipRect(mLeftDividerLeft, 0, mRightDividerRight, getBottom());
}
} else {
- x = (getRight() - getLeft()) / 2f;
+ if (mAlign == LEFT) {
+ x = getLeft() + mSidePadding;
+ } else if (mAlign == RIGHT) {
+ x = getRight() - getMaxTextSize() - mSidePadding;
+ } else {
+ x = (getRight() - getLeft()) / 2f;
+ }
+
y = mCurrentScrollOffset;
if (mRealWheelItemCount < DEFAULT_WHEEL_ITEM_COUNT) {
canvas.clipRect(0, mTopDividerTop, getRight(), mBottomDividerBottom);
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index 3f2a4e0..cad2fe8 100644
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -56,5 +56,11 @@
+
+
+
+
+
+