@@ -71,7 +71,6 @@ public enum ACTION {
7171 int itemsVisible ;
7272
7373 int measuredHeight ;
74- int measuredWidth ;
7574 int paddingLeft = 0 ;
7675 int paddingRight = 0 ;
7776
@@ -156,7 +155,6 @@ private void remeasure() {
156155 halfCircumference = (int ) (maxTextHeight * lineSpacingMultiplier * (itemsVisible - 1 ));
157156 measuredHeight = (int ) ((halfCircumference * 2 ) / Math .PI );
158157 radius = (int ) (halfCircumference / Math .PI );
159- measuredWidth = maxTextWidth + paddingLeft + paddingRight ;
160158 firstLineY = (int ) ((measuredHeight - lineSpacingMultiplier * maxTextHeight ) / 2.0F );
161159 secondLineY = (int ) ((measuredHeight + lineSpacingMultiplier * maxTextHeight ) / 2.0F );
162160 if (initPosition == -1 ) {
@@ -337,8 +335,8 @@ protected void onDraw(Canvas canvas) {
337335 }
338336 k1 ++;
339337 }
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 );
342340
343341 final int itemWidth = ((View )getParent ()).getWidth ();
344342
@@ -369,31 +367,31 @@ protected void onDraw(Canvas canvas) {
369367 if (translateY <= firstLineY && maxTextHeight + translateY >= firstLineY ) {
370368 // 条目经过第一条线
371369 canvas .save ();
372- canvas .clipRect (0 , 0 , measuredWidth , firstLineY - translateY );
370+ canvas .clipRect (0 , 0 , getWidth () , firstLineY - translateY );
373371 canvas .drawText (text , getTextX (text , paintOuterText , tempRect ), maxTextHeight , paintOuterText );
374372 canvas .restore ();
375373 canvas .save ();
376- canvas .clipRect (0 , firstLineY - translateY , measuredWidth , (int ) (itemHeight ));
374+ canvas .clipRect (0 , firstLineY - translateY , getWidth () , (int ) (itemHeight ));
377375 canvas .drawText (text , getTextX (text , paintCenterText , tempRect ), maxTextHeight , paintCenterText );
378376 canvas .restore ();
379377 } else if (translateY <= secondLineY && maxTextHeight + translateY >= secondLineY ) {
380378 // 条目经过第二条线
381379 canvas .save ();
382- canvas .clipRect (0 , 0 , measuredWidth , secondLineY - translateY );
380+ canvas .clipRect (0 , 0 , getWidth () , secondLineY - translateY );
383381 canvas .drawText (text , getTextX (text , paintCenterText , tempRect ), maxTextHeight , paintCenterText );
384382 canvas .restore ();
385383 canvas .save ();
386- canvas .clipRect (0 , secondLineY - translateY , measuredWidth , (int ) (itemHeight ));
384+ canvas .clipRect (0 , secondLineY - translateY , getWidth () , (int ) (itemHeight ));
387385 canvas .drawText (text , getTextX (text , paintOuterText , tempRect ), maxTextHeight , paintOuterText );
388386 canvas .restore ();
389387 } else if (translateY >= firstLineY && maxTextHeight + translateY <= secondLineY ) {
390388 // 中间条目
391- canvas .clipRect (0 , 0 , measuredWidth , (int ) (itemHeight ));
389+ canvas .clipRect (0 , 0 , getWidth () , (int ) (itemHeight ));
392390 canvas .drawText (text , getTextX (text , paintCenterText , tempRect ), maxTextHeight , paintCenterText );
393391 selectedItem = items .indexOf (text );
394392 } else {
395393 // 其他条目
396- canvas .clipRect (0 , 0 , measuredWidth , (int ) (itemHeight ));
394+ canvas .clipRect (0 , 0 , getWidth () , (int ) (itemHeight ));
397395 canvas .drawText (text , getTextX (text , paintOuterText , tempRect ), maxTextHeight , paintOuterText );
398396 }
399397 canvas .restore ();
@@ -407,15 +405,13 @@ private int getTextX(String a, Paint paint, Rect rect) {
407405 paint .getTextBounds (a , 0 , a .length (), rect );
408406 // 获取到的是实际文字宽度
409407 int textWidth = rect .width ();
410- // 转换成绘制文字宽度
411- textWidth *= scaleX ;
412- return (measuredWidth - textWidth ) / 2 ;
408+ return (getWidth () - textWidth ) / 2 ;
413409 }
414410
415411 @ Override
416412 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
417413 remeasure ();
418- setMeasuredDimension (measuredWidth , measuredHeight );
414+ setMeasuredDimension (getDefaultSize ( getSuggestedMinimumWidth (), widthMeasureSpec ) , measuredHeight );
419415 }
420416
421417 @ Override
0 commit comments