@@ -71,7 +71,6 @@ public enum ACTION {
71
71
int itemsVisible ;
72
72
73
73
int measuredHeight ;
74
- int measuredWidth ;
75
74
int paddingLeft = 0 ;
76
75
int paddingRight = 0 ;
77
76
@@ -156,7 +155,6 @@ private void remeasure() {
156
155
halfCircumference = (int ) (maxTextHeight * lineSpacingMultiplier * (itemsVisible - 1 ));
157
156
measuredHeight = (int ) ((halfCircumference * 2 ) / Math .PI );
158
157
radius = (int ) (halfCircumference / Math .PI );
159
- measuredWidth = maxTextWidth + paddingLeft + paddingRight ;
160
158
firstLineY = (int ) ((measuredHeight - lineSpacingMultiplier * maxTextHeight ) / 2.0F );
161
159
secondLineY = (int ) ((measuredHeight + lineSpacingMultiplier * maxTextHeight ) / 2.0F );
162
160
if (initPosition == -1 ) {
@@ -337,8 +335,8 @@ protected void onDraw(Canvas canvas) {
337
335
}
338
336
k1 ++;
339
337
}
340
- canvas .drawLine (0.0F , firstLineY , measuredWidth , firstLineY , paintIndicator );
341
- canvas .drawLine (0.0F , secondLineY , measuredWidth , secondLineY , paintIndicator );
338
+ canvas .drawLine (0.0F , firstLineY , getWidth () , firstLineY , paintIndicator );
339
+ canvas .drawLine (0.0F , secondLineY , getWidth () , secondLineY , paintIndicator );
342
340
343
341
final int itemWidth = ((View )getParent ()).getWidth ();
344
342
@@ -369,31 +367,31 @@ protected void onDraw(Canvas canvas) {
369
367
if (translateY <= firstLineY && maxTextHeight + translateY >= firstLineY ) {
370
368
// 条目经过第一条线
371
369
canvas .save ();
372
- canvas .clipRect (0 , 0 , measuredWidth , firstLineY - translateY );
370
+ canvas .clipRect (0 , 0 , getWidth () , firstLineY - translateY );
373
371
canvas .drawText (text , getTextX (text , paintOuterText , tempRect ), maxTextHeight , paintOuterText );
374
372
canvas .restore ();
375
373
canvas .save ();
376
- canvas .clipRect (0 , firstLineY - translateY , measuredWidth , (int ) (itemHeight ));
374
+ canvas .clipRect (0 , firstLineY - translateY , getWidth () , (int ) (itemHeight ));
377
375
canvas .drawText (text , getTextX (text , paintCenterText , tempRect ), maxTextHeight , paintCenterText );
378
376
canvas .restore ();
379
377
} else if (translateY <= secondLineY && maxTextHeight + translateY >= secondLineY ) {
380
378
// 条目经过第二条线
381
379
canvas .save ();
382
- canvas .clipRect (0 , 0 , measuredWidth , secondLineY - translateY );
380
+ canvas .clipRect (0 , 0 , getWidth () , secondLineY - translateY );
383
381
canvas .drawText (text , getTextX (text , paintCenterText , tempRect ), maxTextHeight , paintCenterText );
384
382
canvas .restore ();
385
383
canvas .save ();
386
- canvas .clipRect (0 , secondLineY - translateY , measuredWidth , (int ) (itemHeight ));
384
+ canvas .clipRect (0 , secondLineY - translateY , getWidth () , (int ) (itemHeight ));
387
385
canvas .drawText (text , getTextX (text , paintOuterText , tempRect ), maxTextHeight , paintOuterText );
388
386
canvas .restore ();
389
387
} else if (translateY >= firstLineY && maxTextHeight + translateY <= secondLineY ) {
390
388
// 中间条目
391
- canvas .clipRect (0 , 0 , measuredWidth , (int ) (itemHeight ));
389
+ canvas .clipRect (0 , 0 , getWidth () , (int ) (itemHeight ));
392
390
canvas .drawText (text , getTextX (text , paintCenterText , tempRect ), maxTextHeight , paintCenterText );
393
391
selectedItem = items .indexOf (text );
394
392
} else {
395
393
// 其他条目
396
- canvas .clipRect (0 , 0 , measuredWidth , (int ) (itemHeight ));
394
+ canvas .clipRect (0 , 0 , getWidth () , (int ) (itemHeight ));
397
395
canvas .drawText (text , getTextX (text , paintOuterText , tempRect ), maxTextHeight , paintOuterText );
398
396
}
399
397
canvas .restore ();
@@ -407,15 +405,13 @@ private int getTextX(String a, Paint paint, Rect rect) {
407
405
paint .getTextBounds (a , 0 , a .length (), rect );
408
406
// 获取到的是实际文字宽度
409
407
int textWidth = rect .width ();
410
- // 转换成绘制文字宽度
411
- textWidth *= scaleX ;
412
- return (measuredWidth - textWidth ) / 2 ;
408
+ return (getWidth () - textWidth ) / 2 ;
413
409
}
414
410
415
411
@ Override
416
412
protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
417
413
remeasure ();
418
- setMeasuredDimension (measuredWidth , measuredHeight );
414
+ setMeasuredDimension (getDefaultSize ( getSuggestedMinimumWidth (), widthMeasureSpec ) , measuredHeight );
419
415
}
420
416
421
417
@ Override
0 commit comments