Rotate text inside wheel of fortune - Android
up vote
2
down vote
favorite
I am using this library to make a wheel of fortune to my app. I have edited some things to make it look like I want but there's something that I couldn't achieve.
I have this: Look at the text direction
I want this: Look at the text direction

I couldn't rotate the text values like the second image.
Here's the class that I think is used to draw the text:
public class PielView extends View
private RectF mRange = new RectF();
private int mRadius;
private Paint mArcPaint;
private Paint mBackgroundPaint;
private Paint mTextPaint;
private float mStartAngle = 0;
private int mCenter;
private int mPadding;
private int mTargetIndex;
private int mRoundOfNumber = 4;
private boolean isRunning = false;
private int defaultBackgroundColor = -1;
private Drawable drawableCenterImage;
private int textColor = 0xffffffff;
private void init()
mArcPaint = new Paint();
mArcPaint.setAntiAlias(true);
mArcPaint.setDither(true);
mTextPaint = new Paint();
mTextPaint.setColor(textColor);
mTextPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,14,
getResources().getDisplayMetrics()));
mRange = new RectF(mPadding, mPadding, mPadding+mRadius, mPadding+mRadius);
private void drawText(Canvas canvas, float tmpAngle, float sweepAngle, String mStr)
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);
@Override
protected void onDraw(Canvas canvas)
super.onDraw(canvas);
if (mLuckyItemList == null)
return;
drawBackgroundColor(canvas, defaultBackgroundColor);
init();
float tmpAngle = mStartAngle;
float sweepAngle = 360 / mLuckyItemList.size();
for(int i = 0; i < mLuckyItemList.size(); i++)
mArcPaint.setColor(mLuckyItemList.get(i).color);
canvas.drawArc(mRange, tmpAngle, sweepAngle, true, mArcPaint);
drawText(canvas, tmpAngle, sweepAngle, mLuckyItemList.get(i).text);
drawImage(canvas, tmpAngle, BitmapFactory.decodeResource(getResources(), mLuckyItemList.get(i).icon));
tmpAngle += sweepAngle;
add a comment |
up vote
2
down vote
favorite
I am using this library to make a wheel of fortune to my app. I have edited some things to make it look like I want but there's something that I couldn't achieve.
I have this: Look at the text direction
I want this: Look at the text direction

I couldn't rotate the text values like the second image.
Here's the class that I think is used to draw the text:
public class PielView extends View
private RectF mRange = new RectF();
private int mRadius;
private Paint mArcPaint;
private Paint mBackgroundPaint;
private Paint mTextPaint;
private float mStartAngle = 0;
private int mCenter;
private int mPadding;
private int mTargetIndex;
private int mRoundOfNumber = 4;
private boolean isRunning = false;
private int defaultBackgroundColor = -1;
private Drawable drawableCenterImage;
private int textColor = 0xffffffff;
private void init()
mArcPaint = new Paint();
mArcPaint.setAntiAlias(true);
mArcPaint.setDither(true);
mTextPaint = new Paint();
mTextPaint.setColor(textColor);
mTextPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,14,
getResources().getDisplayMetrics()));
mRange = new RectF(mPadding, mPadding, mPadding+mRadius, mPadding+mRadius);
private void drawText(Canvas canvas, float tmpAngle, float sweepAngle, String mStr)
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);
@Override
protected void onDraw(Canvas canvas)
super.onDraw(canvas);
if (mLuckyItemList == null)
return;
drawBackgroundColor(canvas, defaultBackgroundColor);
init();
float tmpAngle = mStartAngle;
float sweepAngle = 360 / mLuckyItemList.size();
for(int i = 0; i < mLuckyItemList.size(); i++)
mArcPaint.setColor(mLuckyItemList.get(i).color);
canvas.drawArc(mRange, tmpAngle, sweepAngle, true, mArcPaint);
drawText(canvas, tmpAngle, sweepAngle, mLuckyItemList.get(i).text);
drawImage(canvas, tmpAngle, BitmapFactory.decodeResource(getResources(), mLuckyItemList.get(i).icon));
tmpAngle += sweepAngle;
Broken link for second immage
– Marcos Vasconcelos
Aug 9 at 17:31
@MarcosVasconcelos Really? well, I have uploaded it again
– Jorge Requez
Aug 9 at 18:35
1
Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
– Marcos Vasconcelos
Aug 9 at 19:46
I solved my problem, thank you anyway!
– Jorge Requez
Aug 9 at 20:55
My solution worked or something else?
– Marcos Vasconcelos
Aug 9 at 21:01
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am using this library to make a wheel of fortune to my app. I have edited some things to make it look like I want but there's something that I couldn't achieve.
I have this: Look at the text direction
I want this: Look at the text direction

I couldn't rotate the text values like the second image.
Here's the class that I think is used to draw the text:
public class PielView extends View
private RectF mRange = new RectF();
private int mRadius;
private Paint mArcPaint;
private Paint mBackgroundPaint;
private Paint mTextPaint;
private float mStartAngle = 0;
private int mCenter;
private int mPadding;
private int mTargetIndex;
private int mRoundOfNumber = 4;
private boolean isRunning = false;
private int defaultBackgroundColor = -1;
private Drawable drawableCenterImage;
private int textColor = 0xffffffff;
private void init()
mArcPaint = new Paint();
mArcPaint.setAntiAlias(true);
mArcPaint.setDither(true);
mTextPaint = new Paint();
mTextPaint.setColor(textColor);
mTextPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,14,
getResources().getDisplayMetrics()));
mRange = new RectF(mPadding, mPadding, mPadding+mRadius, mPadding+mRadius);
private void drawText(Canvas canvas, float tmpAngle, float sweepAngle, String mStr)
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);
@Override
protected void onDraw(Canvas canvas)
super.onDraw(canvas);
if (mLuckyItemList == null)
return;
drawBackgroundColor(canvas, defaultBackgroundColor);
init();
float tmpAngle = mStartAngle;
float sweepAngle = 360 / mLuckyItemList.size();
for(int i = 0; i < mLuckyItemList.size(); i++)
mArcPaint.setColor(mLuckyItemList.get(i).color);
canvas.drawArc(mRange, tmpAngle, sweepAngle, true, mArcPaint);
drawText(canvas, tmpAngle, sweepAngle, mLuckyItemList.get(i).text);
drawImage(canvas, tmpAngle, BitmapFactory.decodeResource(getResources(), mLuckyItemList.get(i).icon));
tmpAngle += sweepAngle;
I am using this library to make a wheel of fortune to my app. I have edited some things to make it look like I want but there's something that I couldn't achieve.
I have this: Look at the text direction
I want this: Look at the text direction

I couldn't rotate the text values like the second image.
Here's the class that I think is used to draw the text:
public class PielView extends View
private RectF mRange = new RectF();
private int mRadius;
private Paint mArcPaint;
private Paint mBackgroundPaint;
private Paint mTextPaint;
private float mStartAngle = 0;
private int mCenter;
private int mPadding;
private int mTargetIndex;
private int mRoundOfNumber = 4;
private boolean isRunning = false;
private int defaultBackgroundColor = -1;
private Drawable drawableCenterImage;
private int textColor = 0xffffffff;
private void init()
mArcPaint = new Paint();
mArcPaint.setAntiAlias(true);
mArcPaint.setDither(true);
mTextPaint = new Paint();
mTextPaint.setColor(textColor);
mTextPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,14,
getResources().getDisplayMetrics()));
mRange = new RectF(mPadding, mPadding, mPadding+mRadius, mPadding+mRadius);
private void drawText(Canvas canvas, float tmpAngle, float sweepAngle, String mStr)
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);
@Override
protected void onDraw(Canvas canvas)
super.onDraw(canvas);
if (mLuckyItemList == null)
return;
drawBackgroundColor(canvas, defaultBackgroundColor);
init();
float tmpAngle = mStartAngle;
float sweepAngle = 360 / mLuckyItemList.size();
for(int i = 0; i < mLuckyItemList.size(); i++)
mArcPaint.setColor(mLuckyItemList.get(i).color);
canvas.drawArc(mRange, tmpAngle, sweepAngle, true, mArcPaint);
drawText(canvas, tmpAngle, sweepAngle, mLuckyItemList.get(i).text);
drawImage(canvas, tmpAngle, BitmapFactory.decodeResource(getResources(), mLuckyItemList.get(i).icon));
tmpAngle += sweepAngle;
edited Aug 9 at 18:32
asked Aug 9 at 16:39
Jorge Requez
4919
4919
Broken link for second immage
– Marcos Vasconcelos
Aug 9 at 17:31
@MarcosVasconcelos Really? well, I have uploaded it again
– Jorge Requez
Aug 9 at 18:35
1
Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
– Marcos Vasconcelos
Aug 9 at 19:46
I solved my problem, thank you anyway!
– Jorge Requez
Aug 9 at 20:55
My solution worked or something else?
– Marcos Vasconcelos
Aug 9 at 21:01
add a comment |
Broken link for second immage
– Marcos Vasconcelos
Aug 9 at 17:31
@MarcosVasconcelos Really? well, I have uploaded it again
– Jorge Requez
Aug 9 at 18:35
1
Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
– Marcos Vasconcelos
Aug 9 at 19:46
I solved my problem, thank you anyway!
– Jorge Requez
Aug 9 at 20:55
My solution worked or something else?
– Marcos Vasconcelos
Aug 9 at 21:01
Broken link for second immage
– Marcos Vasconcelos
Aug 9 at 17:31
Broken link for second immage
– Marcos Vasconcelos
Aug 9 at 17:31
@MarcosVasconcelos Really? well, I have uploaded it again
– Jorge Requez
Aug 9 at 18:35
@MarcosVasconcelos Really? well, I have uploaded it again
– Jorge Requez
Aug 9 at 18:35
1
1
Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
– Marcos Vasconcelos
Aug 9 at 19:46
Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
– Marcos Vasconcelos
Aug 9 at 19:46
I solved my problem, thank you anyway!
– Jorge Requez
Aug 9 at 20:55
I solved my problem, thank you anyway!
– Jorge Requez
Aug 9 at 20:55
My solution worked or something else?
– Marcos Vasconcelos
Aug 9 at 21:01
My solution worked or something else?
– Marcos Vasconcelos
Aug 9 at 21:01
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51772117%2frotate-text-inside-wheel-of-fortune-android%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Broken link for second immage
– Marcos Vasconcelos
Aug 9 at 17:31
@MarcosVasconcelos Really? well, I have uploaded it again
– Jorge Requez
Aug 9 at 18:35
1
Well.. thats totally something about ythe tmpAngle from drawText, try to add Math.radians(45) to it
– Marcos Vasconcelos
Aug 9 at 19:46
I solved my problem, thank you anyway!
– Jorge Requez
Aug 9 at 20:55
My solution worked or something else?
– Marcos Vasconcelos
Aug 9 at 21:01