涂料类绘制文本 [英] Paint Class to draw Text

查看:142
本文介绍了涂料类绘制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画在运行时文本,但我想画有三个词的文本。要求是,这些话应该垂直堆叠。

I wanted to draw a Text at runtime but I wanted to draw a text that has three words. requirement is these words should stack vertically.

我可以绘制一个文本 - 这里是尝试

I am able to draw it for one text - Here is the attempt.

protected override void OnDraw(Canvas canvas)
    {
        base.OnDraw(canvas);

        paint.SetStyle(Paint.Style.Stroke);
        paint.AntiAlias = true;
        paint.Dither = true;
        paint.StrokeWidth = 5;
        paint.SetARGB(255, 255, 255, 255);


        textPaint.AntiAlias = true;
        textPaint.SetARGB(255, 255, 255, 255);
        textPaint.TextSize = 30;

        string firstText = "Text1";

        textPaint.TextAlign = Android.Graphics.Paint.Align.Center;

        canvas.DrawCircle(centerCircle.X, centerCircle.Y, circleRadius, paint);

        canvas.DrawText(firstText, centerCircle.X, centerCircle.Y, textPaint);

    }

我没有得到如何画下一个下面的文本2 - 我想firstText =文本1 \\ nText2,但没有成功。

I am not getting how to draw next Text2 below - I tried firstText="Text1\nText2" but not successful.

请仅供参考 - 我刚才用 C#Xamarin.Android 启动机器人。任何帮助和指针是AP preciated。
感谢:)

Please FYI - I have just started android using C# Xamarin.Android. any help and pointer is appreciated. Thanks :)

推荐答案

更改文本的位置:

canvas.DrawText(firstText, centerCircle.X, centerCircle.Y - 50, textPaint);
canvas.DrawText(secondText, centerCircle.X, centerCircle.Y, textPaint);
canvas.DrawText(thirdText, centerCircle.X, centerCircle.Y + 50, textPaint);

如果要居中在圈内使用文本 measureText 油漆的方法

If you want to center the text in the circle use measureText method of Paint.

这篇关于涂料类绘制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆