@@ -105,7 +105,7 @@ public class SmartMaterialSpinner<T> extends AppCompatSpinner implements Adapter
105
105
private int floatingLabelTopSpacing ;
106
106
private int floatingLabelBottomSpacing ;
107
107
private int floatingLabelInsideSpacing ;
108
- private int rightLeftSpinnerPadding ;
108
+ private int leftRightSpinnerPadding ;
109
109
private int minContentHeight ;
110
110
private int arrowPaddingLeft ;
111
111
private int arrowPaddingTop ;
@@ -273,7 +273,7 @@ private void initAttributes(Context context, AttributeSet attrs) {
273
273
minNbErrorLine = typedArray .getInt (R .styleable .SmartMaterialSpinner_smsp_nbErrorLine , 1 );
274
274
currentNbErrorLines = minNbErrorLine ;
275
275
alignLabel = typedArray .getBoolean (R .styleable .SmartMaterialSpinner_smsp_alignLabel , true );
276
- underlineSize = typedArray .getDimension (R .styleable .SmartMaterialSpinner_smsp_underlineSize , 0.6f );
276
+ underlineSize = typedArray .getDimension (R .styleable .SmartMaterialSpinner_smsp_underlineSize , getResources (). getDimensionPixelSize ( R . dimen . smsp_underline_size ) );
277
277
arrowColor = typedArray .getColor (R .styleable .SmartMaterialSpinner_smsp_arrowColor , baseColor );
278
278
arrowSize = typedArray .getDimension (R .styleable .SmartMaterialSpinner_smsp_arrowSize , dpToPx (DEFAULT_ARROW_WIDTH_DP ));
279
279
enableErrorLabel = typedArray .getBoolean (R .styleable .SmartMaterialSpinner_smsp_enableErrorLabel , true );
@@ -359,11 +359,12 @@ public void onGlobalLayout() {
359
359
SmartMaterialSpinner .this .getViewTreeObserver ().removeOnGlobalLayoutListener (this );
360
360
}
361
361
if (getWidth () != 0 && getHeight () != 0 ) {
362
- SmartMaterialSpinner .this .setDropDownWidth (getWidth ());
362
+ SmartMaterialSpinner .this .setDropDownWidth (getWidth () - leftRightSpinnerPadding * 2 );
363
363
if (getDropDownVerticalOffset () <= 0 ) {
364
364
int underlineHeight = dpToPx (underlineSize );
365
365
int underlineStartY = getHeight () - getPaddingBottom () + underlineTopSpacing ;
366
366
SmartMaterialSpinner .this .setDropDownVerticalOffset (underlineStartY + underlineHeight );
367
+ SmartMaterialSpinner .this .setDropDownHorizontalOffset (SmartMaterialSpinner .this .getDropDownHorizontalOffset () + leftRightSpinnerPadding - getPaddingLeft ());
367
368
dropdownHeightUpdated = true ;
368
369
}
369
370
}
@@ -448,13 +449,14 @@ private void initDimensions(Context context, AttributeSet attrs) {
448
449
errorTextPaddingBottom = getResources ().getDimensionPixelSize (R .dimen .smsp_error_text_padding_bottom );
449
450
floatingLabelTopSpacing = getResources ().getDimensionPixelSize (R .dimen .smsp_floating_label_top_spacing );
450
451
floatingLabelBottomSpacing = getResources ().getDimensionPixelSize (R .dimen .smsp_floating_label_bottom_spacing );
451
- rightLeftSpinnerPadding = alignLabel ? getResources ().getDimensionPixelSize (R .dimen .smsp_right_left_spinner_padding ) : 0 ;
452
+ //leftRightSpinnerPadding = alignLabel ? getResources().getDimensionPixelSize(R.dimen.smsp_left_right_spinner_padding) : 0;
453
+ leftRightSpinnerPadding = typedArray .getDimensionPixelSize (R .styleable .SmartMaterialSpinner_smsp_paddingLeftRight , getResources ().getDimensionPixelSize (R .dimen .smsp_left_right_spinner_padding ));
452
454
floatingLabelInsideSpacing = getResources ().getDimensionPixelSize (R .dimen .smsp_floating_label_inside_spacing );
453
455
errorTextPaddingTop = getResources ().getDimensionPixelSize (R .dimen .smsp_error_text_padding_top );
454
456
errorTextPaddingTopBottom = getResources ().getDimensionPixelSize (R .dimen .smsp_error_text_padding_top_bottom );
455
457
minContentHeight = getResources ().getDimensionPixelSize (R .dimen .smsp_min_content_height );
456
458
457
- arrowPaddingLeft = typedArray .getDimensionPixelSize (R .styleable .SmartMaterialSpinner_smsp_arrowPaddingLeft , 0 );
459
+ arrowPaddingLeft = typedArray .getDimensionPixelSize (R .styleable .SmartMaterialSpinner_smsp_arrowPaddingLeft , getResources (). getDimensionPixelSize ( R . dimen . smsp_default_arrow_padding_left ) );
458
460
arrowPaddingTop = typedArray .getDimensionPixelSize (R .styleable .SmartMaterialSpinner_smsp_arrowPaddingTop , 0 );
459
461
arrowPaddingRight = typedArray .getDimensionPixelSize (R .styleable .SmartMaterialSpinner_smsp_arrowPaddingRight , getResources ().getDimensionPixelSize (R .dimen .smsp_default_arrow_padding_right ));
460
462
arrowPaddingBottom = typedArray .getDimensionPixelSize (R .styleable .SmartMaterialSpinner_smsp_arrowPaddingBottom , 0 );
@@ -539,7 +541,7 @@ private float pxToDp(float px) {
539
541
540
542
private boolean needScrollingAnimation () {
541
543
if (errorText != null ) {
542
- float screenWidth = getWidth () - rightLeftSpinnerPadding ;
544
+ float screenWidth = getWidth () - leftRightSpinnerPadding ;
543
545
float errorTextWidth = errorTextPaint .measureText (errorText .toString (), 0 , errorText .length ());
544
546
return errorTextWidth > screenWidth ;
545
547
}
@@ -610,8 +612,8 @@ private AppCompatActivity scanForActivity(Context context) {
610
612
@ Override
611
613
protected void onDraw (Canvas canvas ) {
612
614
super .onDraw (canvas );
613
- int startX = 0 ;
614
- int endX = getWidth ();
615
+ int startX = leftRightSpinnerPadding ;
616
+ int endX = getWidth () - leftRightSpinnerPadding ;
615
617
int lineHeight = dpToPx (underlineSize );
616
618
617
619
if (getHeight () != 0 && !dropdownHeightUpdated ) {
@@ -633,7 +635,7 @@ protected void onDraw(Canvas canvas) {
633
635
prepareBottomPadding ();
634
636
}
635
637
canvas .save ();
636
- canvas .translate (startX + rightLeftSpinnerPadding - errorLabelPosX , startYErrorLabel - dpToPx (4 ));
638
+ canvas .translate (startX - errorLabelPosX , startYErrorLabel - dpToPx (4 ));
637
639
staticLayout .draw (canvas );
638
640
canvas .restore ();
639
641
} else {
@@ -642,11 +644,11 @@ protected void onDraw(Canvas canvas) {
642
644
isErrorScrollPaddingInvoked = true ;
643
645
updateBottomPadding ();
644
646
}
645
- canvas .drawText (errorText .toString (), startX + rightLeftSpinnerPadding - errorLabelPosX , startYErrorLabel + errorTextHeight , errorTextPaint );
647
+ canvas .drawText (errorText .toString (), startX - errorLabelPosX , startYErrorLabel + errorTextHeight , errorTextPaint );
646
648
if (errorLabelPosX > 0 ) {
647
649
canvas .save ();
648
650
canvas .translate (errorTextPaint .measureText (errorText .toString ()) + getWidth () / 2F , 0 );
649
- canvas .drawText (errorText .toString (), startX + rightLeftSpinnerPadding - errorLabelPosX , startYErrorLabel + errorTextHeight , errorTextPaint );
651
+ canvas .drawText (errorText .toString (), startX - errorLabelPosX , startYErrorLabel + errorTextHeight , errorTextPaint );
650
652
canvas .restore ();
651
653
}
652
654
}
@@ -674,13 +676,13 @@ protected void onDraw(Canvas canvas) {
674
676
floatLabelTextPaint .setTextSize (floatingLabelSize );
675
677
String textToDraw = floatingLabelText != null ? floatingLabelText .toString () : hint .toString ();
676
678
if (isRtl ) {
677
- canvas .drawText (textToDraw , getWidth () - rightLeftSpinnerPadding - floatLabelTextPaint .measureText (textToDraw ), startYFloatingLabel , floatLabelTextPaint );
679
+ canvas .drawText (textToDraw , getWidth () - floatLabelTextPaint .measureText (textToDraw ), startYFloatingLabel , floatLabelTextPaint );
678
680
} else {
679
- canvas .drawText (textToDraw , startX + rightLeftSpinnerPadding , startYFloatingLabel , floatLabelTextPaint );
681
+ canvas .drawText (textToDraw , startX + getPaddingLeft () , startYFloatingLabel , floatLabelTextPaint );
680
682
}
681
683
}
682
- // drawSelector(canvas, (getWidth() - rightLeftSpinnerPadding - arrowPaddingRight + arrowPaddingLeft), getPaddingTop() + dpToPx(6) - arrowPaddingBottom + arrowPaddingTop);
683
- drawSelector (canvas , (getWidth () - rightLeftSpinnerPadding - arrowPaddingRight + arrowPaddingLeft ), (int ) (getPaddingTop () - arrowPaddingBottom + arrowPaddingTop + minContentHeight / 2F + itemSize / 2 - floatingLabelTopSpacing ));
684
+ // drawSelector(canvas, (getWidth() - leftRightSpinnerPadding - arrowPaddingRight + arrowPaddingLeft), getPaddingTop() + dpToPx(6) - arrowPaddingBottom + arrowPaddingTop);
685
+ drawSelector (canvas , (getWidth () - leftRightSpinnerPadding - arrowPaddingRight + arrowPaddingLeft ), (int ) (getPaddingTop () - arrowPaddingBottom + arrowPaddingTop + minContentHeight / 2F + itemSize / 2 - floatingLabelTopSpacing ));
684
686
}
685
687
686
688
private void drawSelector (Canvas canvas , int posX , int posY ) {
@@ -1194,7 +1196,7 @@ public boolean isAlignLabel() {
1194
1196
1195
1197
public void setAlignLabel (boolean alignLabel ) {
1196
1198
this .alignLabel = alignLabel ;
1197
- rightLeftSpinnerPadding = alignLabel ? getResources ().getDimensionPixelSize (R .dimen .smsp_right_left_spinner_padding ) : 0 ;
1199
+ leftRightSpinnerPadding = alignLabel ? getResources ().getDimensionPixelSize (R .dimen .smsp_left_right_spinner_padding ) : 0 ;
1198
1200
invalidate ();
1199
1201
}
1200
1202
@@ -1610,6 +1612,15 @@ public void setArrowPadding(int left, int top, int right, int bottom) {
1610
1612
invalidate ();
1611
1613
}
1612
1614
1615
+ public int getLeftRightSpinnerPadding () {
1616
+ return leftRightSpinnerPadding ;
1617
+ }
1618
+
1619
+ public void setLeftRightSpinnerPadding (int leftRightSpinnerPadding ) {
1620
+ this .leftRightSpinnerPadding = dpToPx (leftRightSpinnerPadding );
1621
+ invalidate ();
1622
+ }
1623
+
1613
1624
public void setOnEmptySpinnerClickListener (OnEmptySpinnerClickListener onEmptySpinnerClickListener ) {
1614
1625
this .onEmptySpinnerClickListener = onEmptySpinnerClickListener ;
1615
1626
}
@@ -1775,7 +1786,7 @@ private View buildView(int position, View convertView, ViewGroup parent, boolean
1775
1786
return getItemView (convertView , parent , isDropDownView );
1776
1787
} else {
1777
1788
TextView textView = (TextView ) getItemView (convertView , parent , isDropDownView );
1778
- // textView.setHeight(0);
1789
+ //textView.setHeight(0);
1779
1790
textView .setText (getResources ().getString (R .string .select_item ));
1780
1791
return textView ;
1781
1792
}
@@ -1830,7 +1841,7 @@ private void updateSpinnerItemStyle(ViewGroup parent, TextView textView, boolean
1830
1841
} else {
1831
1842
textView .setTextColor (SmartMaterialSpinner .this .isEnabled () ? hintColor : disabledColor );
1832
1843
measureItemText (textView .getText ().toString ());
1833
- textView .setPadding (textView .getPaddingLeft (), textView .getPaddingTop (), (int ) (arrowPaddingRight + itemTextHeight ), textView .getPaddingBottom ());
1844
+ textView .setPadding (textView .getPaddingLeft () + leftRightSpinnerPadding , textView .getPaddingTop (), (int ) (arrowPaddingRight + itemTextHeight ), textView .getPaddingBottom ());
1834
1845
}
1835
1846
} else {
1836
1847
if (isDropDownView ) {
@@ -1844,7 +1855,7 @@ private void updateSpinnerItemStyle(ViewGroup parent, TextView textView, boolean
1844
1855
textView .setTextSize (TypedValue .COMPLEX_UNIT_PX , itemSize );
1845
1856
textView .setTextColor (itemColor );
1846
1857
measureItemText (textView .getText ().toString ());
1847
- textView .setPadding (textView .getPaddingLeft (), textView .getPaddingTop (), (int ) (arrowPaddingRight + itemTextHeight ), textView .getPaddingBottom ());
1858
+ textView .setPadding (textView .getPaddingLeft () + leftRightSpinnerPadding , textView .getPaddingTop (), (int ) (arrowPaddingRight + itemTextHeight ), textView .getPaddingBottom ());
1848
1859
}
1849
1860
}
1850
1861
}
0 commit comments