Ejemplo n.º 1
0
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);
            paint.Color    = Pattern.TextColor.ToAndroid();
            paint.TextSize = Android.Util.TypedValue.ApplyDimension(Android.Util.ComplexUnitType.Sp, Pattern.TextSize > 0 ? Pattern.TextSize : 12, Forms.Context.Resources.DisplayMetrics);
            var bounds = new Rect();

            paint.GetTextBounds(Pattern.Text, 0, Pattern.Text.Length, bounds);
            var al = (int)Pattern.TextAlign;
            var x  = Bounds.Left;

            if ((al & 2) == 2)             // center
            {
                x = Bounds.CenterX() - Math.Abs(bounds.CenterX());
            }
            else if ((al & 4) == 4)               // right
            {
                x = Bounds.Right - bounds.Width();
            }
            var y = Bounds.Top + Math.Abs(bounds.Top);

            if ((al & 16) == 16)             // middle
            {
                y = Bounds.CenterY() + Math.Abs(bounds.CenterY());
            }
            else if ((al & 32) == 32)               // bottom
            {
                y = Bounds.Bottom - Math.Abs(bounds.Bottom);
            }
            canvas.DrawText(Pattern.Text.ToCharArray(), 0, Pattern.Text.Length, x, y, paint);
        }