本文整理汇总了C#中Android.Graphics.Paint.Descent方法的典型用法代码示例。如果您正苦于以下问题:C# Paint.Descent方法的具体用法?C# Paint.Descent怎么用?C# Paint.Descent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Paint
的用法示例。
在下文中一共展示了Paint.Descent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AndroidFontMetrics
public AndroidFontMetrics(Paint paint)
{
_widths = new float[NumWidths];
paint.GetTextWidths (_chars, 0, NumWidths, _widths);
Ascent = (int)(Math.Abs (paint.Ascent ()) + 0.5f);
Descent = (int)(paint.Descent ()/2 + 0.5f);
Height = Ascent;
}
示例2: CreateBitmapData
void CreateBitmapData (string str, out byte[] bitmapData, out int width, out int height)
{
Paint paint = new Paint ();
paint.TextSize = 128;
paint.TextAlign = Paint.Align.Left;
paint.SetTypeface (Typeface.Default);
width = height = 256;
float textWidth = paint.MeasureText (str);
using (Bitmap bitmap = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888)) {
Canvas canvas = new Canvas (bitmap);
paint.Color = str != " " ? Color.White : Color.LightGray;
canvas.DrawRect (new Rect (0, 0, width, height), paint);
paint.Color = Color.Black;
canvas.DrawText (str, (256 - textWidth) / 2f, (256 - paint.Descent () - paint.Ascent ()) / 2f, paint);
bitmapData = new byte [width * height * 4];
Java.Nio.ByteBuffer buffer = Java.Nio.ByteBuffer.Allocate (bitmapData.Length);
bitmap.CopyPixelsToBuffer (buffer);
buffer.Rewind ();
buffer.Get (bitmapData, 0, bitmapData.Length);
}
}
示例3: CalcBounds
private Rect CalcBounds(int index, Paint paint)
{
var bounds = new Rect();
var title = GetTitle(index);
bounds.Right = (int)paint.MeasureText(title);
bounds.Bottom = (int)(paint.Descent() - paint.Ascent());
return bounds;
}
示例4: CalcBounds
/**
* Calculate the bounds for a view's title
*
* @param index
* @param paint
* @return
*/
private RectF CalcBounds(int index, Paint paint)
{
//Calculate the text bounds
RectF bounds = new RectF();
bounds.Right = paint.MeasureText(mTitleProvider.GetTitle(index));
bounds.Bottom = paint.Descent() - paint.Ascent();
return bounds;
}
示例5: calcBounds
/**
* Calculate the bounds for a view's title
*
* @param index
* @param paint
* @return
*/
private Rect calcBounds(int index, Paint paint)
{
//Calculate the text bounds
Rect bounds = new Rect();
string title = getTitle(index);
bounds.Right = (int)paint.MeasureText(title, 0, title.Length);
bounds.Bottom = (int)(paint.Descent() - paint.Ascent());
return bounds;
}
示例6: DrawText
public void DrawText(double x, double y, double width, double height, string text, Model.UI.Color textColor, Model.UI.TextAlignment alignment)
{
Paint paint = new Paint();
switch (alignment)
{
case Model.UI.TextAlignment.Left:
paint.TextAlign = Android.Graphics.Paint.Align.Left;
break;
case Model.UI.TextAlignment.Right:
paint.TextAlign = Android.Graphics.Paint.Align.Right;
break;
case Model.UI.TextAlignment.Centered:
paint.TextAlign = Android.Graphics.Paint.Align.Center;
break;
default:
break;
}
string[] lines = text.Split('\n');
double minFontSize = height / lines.Length;
paint.AntiAlias = true;
paint.Color = new Android.Graphics.Color((byte)textColor.Red, (byte)textColor.Green, (byte)textColor.Blue, (byte)(textColor.Alpha * 255));
foreach (string line in lines)
{
paint.TextSize = (float)(height/ lines.Length);
if (paint.MeasureText(line) > width)
{
minFontSize = Math.Min(minFontSize, width / paint.MeasureText(line) * (height / lines.Length));
}
}
paint.TextSize = (float)minFontSize;
for (int index = 0; index < lines.Length; index++)
{
canvas.DrawText(lines[index], (float)(x + (alignment == Model.UI.TextAlignment.Centered ? width / 2 : 0)), (float)(y + height - paint.Descent() - ((height / lines.Length) * (0.5 - index + lines.Length - 1) - paint.TextSize / 2)), paint);
}
}