@@ -156,6 +156,11 @@ public class NumberPicker extends LinearLayout {
156156 */
157157 private static final int DEFAULT_TEXT_ALIGN = CENTER ;
158158
159+ /**
160+ * The default content alignment.
161+ */
162+ private static final int DEFAULT_ALIGN = CENTER ;
163+
159164 /**
160165 * The default color of text.
161166 */
@@ -630,6 +635,16 @@ private enum DividerType {
630635 */
631636 private ViewConfiguration mViewConfiguration ;
632637
638+ /**
639+ * The content alignment.
640+ */
641+ private int mAlign = DEFAULT_ALIGN ;
642+
643+ /**
644+ * The padding applied to the content when it's not centered (align is "left" or "right").
645+ */
646+ private int mSidePadding = 0 ;
647+
633648 /**
634649 * Interface to listen for changes of the current value.
635650 */
@@ -814,6 +829,9 @@ public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
814829 R .styleable .NumberPicker_np_hideWheelUntilFocused , false );
815830 mAccessibilityDescriptionEnabled = attributes .getBoolean (
816831 R .styleable .NumberPicker_np_accessibilityDescriptionEnabled , true );
832+ mAlign = attributes .getInt (R .styleable .NumberPicker_np_align , mAlign );
833+ mSidePadding = attributes .getDimensionPixelSize (
834+ R .styleable .NumberPicker_np_sidePadding , mSidePadding );
817835
818836 // By default LinearLayout that we extend is not drawn. This is
819837 // its draw() method is not called but dispatchDraw() is called
@@ -1767,7 +1785,14 @@ protected void onDraw(Canvas canvas) {
17671785 canvas .clipRect (mLeftDividerLeft , 0 , mRightDividerRight , getBottom ());
17681786 }
17691787 } else {
1770- x = (getRight () - getLeft ()) / 2f ;
1788+ if (mAlign == LEFT ) {
1789+ x = getLeft () + mSidePadding ;
1790+ } else if (mAlign == RIGHT ) {
1791+ x = getRight () - getMaxTextSize () - mSidePadding ;
1792+ } else {
1793+ x = (getRight () - getLeft ()) / 2f ;
1794+ }
1795+
17711796 y = mCurrentScrollOffset ;
17721797 if (mRealWheelItemCount < DEFAULT_WHEEL_ITEM_COUNT ) {
17731798 canvas .clipRect (0 , mTopDividerTop , getRight (), mBottomDividerBottom );
0 commit comments