3

If I want to use DrawText to draw some text on the canvas, but I want the text to end at the center of the screen, how can I do that? I tried setting the x parameter in DrawText to the middle of the screen, and then right aligning inside of the SKPaint definition, but it goes to the right side of the middle, instead of the left.

I feel like this should be fairly simple, but it's not working for me. Help would be appreciated.


appending my question with this code that I'm using to attempt to do what I want ...

SKPaint paint = new SKPaint
{
    Color = SKColors.Blue,
    TextSize = 30,
    TextAlign = SKTextAlign.Right
};

string text = "text";

// rect has the dimensions of the view
var xText = rect.Width / 2;

canvas.DrawText(text, (float)xText, 0, paint);

... Previously to this I was doing a paint.MeasureText(text) but realized to right align would be impossible to do accurately, consistently.

Jimmy
  • 1,299
  • 2
  • 10
  • 14
  • Can you post the code, just to be clear how you're trying to do that? – Timo Salomäki Aug 21 '17 at 16:39
  • I mean the whole setting up parameters, align etc. You can edit your post to add the lines there. – Timo Salomäki Aug 22 '17 at 12:48
  • Yeah, I didn't mean to post that one line. I was typing code and accidentally posted that response. I removed the accidental post now, and edited my question to include some sample code. – Jimmy Aug 22 '17 at 12:54
  • Turns out, what I had actually does exactly what I was trying to do. It was an issue because on the Android device I was using, instead of getting rect.Width, which should have been 300, it was giving me 150, which is right in the middle of my view. So the middle I was getting told was 75, which is actually the left bounds of the view. So everything was off. Anyway, thanks for the responses. – Jimmy Aug 22 '17 at 13:36
  • Good to hear you solved the problem. – Timo Salomäki Aug 22 '17 at 13:37

0 Answers0