From 157c839131c5571060c68457d2aafbc51bb1a551 Mon Sep 17 00:00:00 2001 From: thachdo Date: Mon, 29 Jan 2018 23:17:57 +0800 Subject: [PATCH] Short way to center text --- library/src/main/java/rubikstudio/library/PielView.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/rubikstudio/library/PielView.java b/library/src/main/java/rubikstudio/library/PielView.java index f42b8fe..4921a77 100644 --- a/library/src/main/java/rubikstudio/library/PielView.java +++ b/library/src/main/java/rubikstudio/library/PielView.java @@ -71,6 +71,7 @@ private void init() { mTextPaint.setColor(textColor); mTextPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,14, getResources().getDisplayMetrics())); + mTextPaint.setTextAlign(Paint.Align.CENTER); mRange = new RectF(mPadding, mPadding, mPadding+mRadius, mPadding+mRadius); } @@ -192,12 +193,9 @@ private void drawText(Canvas canvas, float tmpAngle, float sweepAngle, String mS Path path = new Path(); path.addArc(mRange,tmpAngle,sweepAngle); - float textWidth = mTextPaint.measureText(mStr); - int hOffset = (int) (mRadius * Math.PI / mLuckyItemList.size()/2-textWidth/2); - int vOffset = mRadius/2/4; - canvas.drawTextOnPath(mStr, path, hOffset, vOffset, mTextPaint); + canvas.drawTextOnPath(mStr, path, 0, vOffset, mTextPaint); } /**