本文整理汇总了C#中Android.Graphics.Rect.CenterY方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.CenterY方法的具体用法?C# Rect.CenterY怎么用?C# Rect.CenterY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Rect
的用法示例。
在下文中一共展示了Rect.CenterY方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw (canvas);
//create an instance of class Paint, set color and font size
var textPaint = new Paint {
AntiAlias = true,
Color = _textColor,
TextSize = _textSize };
//In order to show text in a middle, we need to know its size
var bounds = new Rect ();
textPaint.GetTextBounds (_text, 0, _text.Length, bounds);
//Now we store font size in bounds variable and can calculate it's position
var x = (Width / 2) - bounds.CenterX ();
var y = (Height / 2) - bounds.CenterY ();
//drawing text with appropriate color and size in the center
canvas.DrawText (_text, x, y, textPaint);
}
示例2: Draw
internal void Draw(Canvas canvas, bool isRound)
{
if (Hidden)
{
return;
}
canvas.Save();
var resizerPaint = new Paint { Color = new Color(255, 255, 255, 200) };
//if (!Focused)
//{
// outlinePaint.Color = Color.White;
// canvas.DrawRect(DrawRect, outlinePaint);
// //canvas.DrawCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width(), resizerPaint);
//}
//else
//{
Rect viewDrawingRect = new Rect();
context.GetDrawingRect(viewDrawingRect);
outlinePaint.Color = Color.White;// new Color(0XFF, 0xFF, 0x8A, 0x00);
focusPaint.Color = new Color(50, 50, 50, 125);
Path path = new Path();
if (isRound)
{
path.AddCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width() / 2, Path.Direction.Cw);
canvas.ClipPath(path, Region.Op.Difference);
canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint);
}
else
{
path.AddRect(new RectF(DrawRect), Path.Direction.Cw);
canvas.ClipPath(path, Region.Op.Difference);
canvas.DrawRect(viewDrawingRect, focusPaint);
}
//canvas.ClipPath(path, Region.Op.Difference);
//if (isRound)
// canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint);
//else
// canvas.DrawRect(viewDrawingRect, focusPaint);
canvas.Restore();
canvas.DrawPath(path, outlinePaint);
var resizerTriangle = new Path();
var resizerOffset = 4;
var triangleSize = resizerSize + resizerOffset;
resizerTriangle.MoveTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - triangleSize);
resizerTriangle.LineTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - resizerOffset);
resizerTriangle.LineTo(DrawRect.Right - triangleSize, DrawRect.Bottom - resizerOffset);
resizerPaint.SetStyle(Paint.Style.Fill);
canvas.DrawPath(resizerTriangle, resizerPaint);
if (isRound)
{
// Draw the rectangle around the round cropper
var roundCropperRectangle = new Path();
roundCropperRectangle.MoveTo(DrawRect.Left, DrawRect.Top);
roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Top);
roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Bottom);
roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Bottom);
roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Top);
resizerPaint.SetStyle(Paint.Style.Stroke);
canvas.DrawPath(roundCropperRectangle, resizerPaint);
}
}
示例3: addArrow
private void addArrow (Rect originRect, int arrowDirection)
{
//Add arrow drawable
ImageView arrowImageView = new ImageView (Application.Context);
Drawable arrowDrawable = null;
int xPos = 0;
int arrowWidth = 0;
int yPos = 0;
int arrowHeight = 0;
//Get correct drawable, and get Width, Height, Xpos and yPos depending on the selected arrow direction
if (arrowDirection == PopoverView.PopoverArrowDirectionUp) {
arrowDrawable = Resources.GetDrawable (popoverArrowUpDrawable);
arrowWidth = arrowDrawable.IntrinsicWidth;
arrowHeight = arrowDrawable.IntrinsicHeight;
xPos = originRect.CenterX () - (arrowWidth / 2) - popoverLayoutRect.Left;
yPos = originRect.Bottom - popoverLayoutRect.Top;
} else if (arrowDirection == PopoverView.PopoverArrowDirectionDown) {
arrowDrawable = Resources.GetDrawable (popoverArrowDownDrawable);
arrowWidth = arrowDrawable.IntrinsicWidth;
arrowHeight = arrowDrawable.IntrinsicHeight;
xPos = originRect.CenterX () - (arrowWidth / 2) - popoverLayoutRect.Left;
yPos = originRect.Top - arrowHeight - popoverLayoutRect.Top;
} else if (arrowDirection == PopoverView.PopoverArrowDirectionLeft) {
arrowDrawable = Resources.GetDrawable (popoverArrowLeftDrawable);
arrowWidth = arrowDrawable.IntrinsicWidth;
arrowHeight = arrowDrawable.IntrinsicHeight;
xPos = originRect.Right - popoverLayoutRect.Left;
yPos = originRect.CenterY () - (arrowHeight / 2) - popoverLayoutRect.Top;
} else if (arrowDirection == PopoverView.PopoverArrowDirectionRight) {
arrowDrawable = Resources.GetDrawable (popoverArrowRightDrawable);
arrowWidth = arrowDrawable.IntrinsicWidth;
arrowHeight = arrowDrawable.IntrinsicHeight;
xPos = originRect.Left - arrowWidth - popoverLayoutRect.Left;
yPos = originRect.CenterY () - (arrowHeight / 2) - popoverLayoutRect.Top;
}
//Set drawable
arrowImageView.SetImageDrawable (arrowDrawable);
//Init layout params
LayoutParams arrowParams = new LayoutParams (arrowWidth, arrowHeight);
arrowParams.LeftMargin = xPos;
arrowParams.TopMargin = yPos;
//add view :)
AddView (arrowImageView, arrowParams);
}
示例4: getRectForArrowLeft
/**
* Calculates the rect for showing the view with Arrow Left
* @param originRect The origin rect
* @return The calculated rect to show the view
*/
private Rect getRectForArrowLeft (Rect originRect)
{
//Get available space
int xAvailable = popoverLayoutRect.Width () - (originRect.Right - popoverLayoutRect.Left);
if (xAvailable < 0)
xAvailable = 0;
int yAvailable = popoverLayoutRect.Height ();
if (yAvailable < 0)
yAvailable = 0;
//Get final width and height
int finalX = xAvailable;
if ((realContentSize.X > 0) && (realContentSize.X < finalX))
finalX = realContentSize.X;
int finalY = yAvailable;
if ((realContentSize.Y > 0) && (realContentSize.Y < finalY))
finalY = realContentSize.Y;
//Get final origin X and Y
int originX = (originRect.Right - popoverLayoutRect.Left);
int originY = (originRect.CenterY () - popoverLayoutRect.Top) - (finalY / 2);
if (originY < 0)
originY = 0;
else if (originY + finalY > popoverLayoutRect.Height ())
originY = popoverLayoutRect.Height () - finalY;
//Create rect
Rect finalRect = new Rect (originX, originY, originX + finalX, originY + finalY);
//And return
return finalRect;
}
示例5: drawLabel
void drawLabel (Canvas canvas, float xCoord, float yCoord, Paint.Align alignment, string label, bool centerVertical = false)
{
var fontColor = Color.White;
var textPaint = new TextPaint ();
textPaint.Color = fontColor;
textPaint.TextSize = fontSize;
textPaint.TextAlign = alignment;
textPaint.SetStyle (Paint.Style.Stroke);
var frame = new Rect ();
textPaint.GetTextBounds (label, 0, label.Length, frame);
if (centerVertical) {
yCoord -= frame.CenterY ();
} else {
yCoord += frame.Height ();
}
canvas.DrawText (label, xCoord, yCoord, textPaint);
}