本文整理汇总了C#中Android.Graphics.Rect.Width方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Width方法的具体用法?C# Rect.Width怎么用?C# Rect.Width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Rect
的用法示例。
在下文中一共展示了Rect.Width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateStartScale
/// <summary>
/// This method will determine the scaling ratio for the image view.
/// </summary>
/// <param name="startBounds">The visible rectangle of the thumbnail.</param>
/// <param name="finalBounds">The visible rectangle of the expanded image view.</param>
/// <returns></returns>
private static float CalculateStartScale(Rect startBounds, Rect finalBounds)
{
float startScale;
// First figure out width-to-height ratio of each rectangle.
float finalBoundsRatio = finalBounds.Width() / (float)finalBounds.Height();
float startBoundsRatio = startBounds.Width() / (float)startBounds.Height();
if (finalBoundsRatio > startBoundsRatio)
{
// Extend start bounds horizontally
startScale = (float)startBounds.Height() / finalBounds.Height();
float startWidth = startScale * finalBounds.Width();
float deltaWidth = (startWidth - startBounds.Width()) / 2;
startBounds.Left -= (int)deltaWidth;
startBounds.Right += (int)deltaWidth;
}
else
{
// Extend start bounds vertically
startScale = (float)startBounds.Width() / finalBounds.Width();
float startHeight = startScale * finalBounds.Height();
float deltaHeight = (startHeight - startBounds.Height()) / 2;
startBounds.Top -= (int)deltaHeight;
startBounds.Bottom += (int)deltaHeight;
}
return startScale;
}
示例2: OnDraw
protected override void OnDraw(Canvas canvas)
{
base.OnDraw (canvas);
var r = new Rect ();
this.GetLocalVisibleRect (r);
var half = r.Width() / 2;
var height = r.Height();
var percentage = (this.Limit - Math.Abs(this.CurrentValue)) / this.Limit;
var paint = new Paint()
{
Color = this.CurrentValue < 0 ? this.negativeColor : this.positiveColor,
StrokeWidth = 5
};
paint.SetStyle(Paint.Style.Fill);
if (this.CurrentValue < 0)
{
var start = (float)percentage * half;
var size = half - start;
canvas.DrawRect (new Rect ((int)start, 0, (int)(start + size), height), paint);
}
else
{
canvas.DrawRect (new Rect((int)half, 0, (int)(half + percentage * half), height), paint);
}
}
示例3: Draw
public override void Draw(Canvas canvas)
{
LoadResources ();
var blackPaint = new Paint () { Color = black.Value };
var whitePaint = new Paint () { Color = white.Value };
XamGame.RenderBoard ((RectangleF rect, Square.ColourNames color) =>
{
var paint = color == Square.ColourNames.White ? whitePaint : blackPaint;
canvas.DrawRect (rect.X, rect.Y, rect.Right, rect.Bottom, paint);
}, (RectangleF rect, object image) =>
{
if (image != null)
canvas.DrawBitmap ((Bitmap) image, rect.Left, rect.Top, null);
});
// New Game button
whitePaint.Color = white.Value;
whitePaint.SetStyle (Paint.Style.Fill);
whitePaint.TextSize = 30;
whitePaint.AntiAlias = true;
Rect bounds = new Rect ();
whitePaint.GetTextBounds ("New Game", 0, 8, bounds);
canvas.DrawText ("New Game", (this.Width - bounds.Width ()) / 2, this.Bottom - (XamGame.BoardUpperLeftCorner.Y - bounds.Height ()) / 2, whitePaint);
whitePaint.Dispose ();
blackPaint.Dispose ();
base.Draw (canvas);
}
示例4: GetBitmapMarker
public Bitmap GetBitmapMarker(Context mContext, int resourceId, string text)
{
Resources resources = mContext.Resources;
float scale = resources.DisplayMetrics.Density;
Bitmap bitmap = BitmapFactory.DecodeResource(resources, resourceId);
Bitmap.Config bitmapConfig = bitmap.GetConfig();
// set default bitmap config if none
if (bitmapConfig == null)
bitmapConfig = Bitmap.Config.Argb8888;
bitmap = bitmap.Copy(bitmapConfig, true);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(PaintFlags.AntiAlias);
paint.Color = global::Android.Graphics.Color.Black;
paint.TextSize = ((int)(14 * scale));
paint.SetShadowLayer(1f, 0f, 1f, global::Android.Graphics.Color.White);
// draw text to the Canvas center
Rect bounds = new Rect();
paint.GetTextBounds(text, 0, text.Length, bounds);
int x = (bitmap.Width - bounds.Width()) / 2;
int y = (bitmap.Height + bounds.Height()) / 2 - 20;
canvas.DrawText(text, x, y, paint);
return bitmap;
}
示例5: OnBoundsChange
protected override void OnBoundsChange (Rect bounds)
{
base.OnBoundsChange (bounds);
if (oval == null)
return;
oval.Set (0, 0, bounds.Width (), bounds.Height ());
}
示例6: OnBoundsChange
protected override void OnBoundsChange (Rect bounds)
{
var width = bounds.Width ();
var height = bounds.Height ();
if (width <= 0 || height <= 0)
return;
if (Picture != null && (currentBitmap == null || currentBitmap.Height != height || currentBitmap.Width != width))
currentBitmap = SvgFactory.MakeBitmapFromPicture(Picture, width, height);
}
示例7: OnBoundsChange
protected override void OnBoundsChange (Rect bounds)
{
base.OnBoundsChange (bounds);
int height = bounds.Height();
int width = bounds.Width();
numRectanglesHorizontal = (int) Math.Ceiling((double)(width / mRectangleSize));
numRectanglesVertical = (int) Math.Ceiling((double)height / mRectangleSize);
generatePatternBitmap();
}
示例8: OnLayout
protected override void OnLayout (bool changed, int l, int t, int r, int b)
{
base.OnLayout (changed, l, t, r, b);
if (changed) {
var drawables = Control.GetCompoundDrawables ();
if (drawables [0] != null) {
Rect drawableBounds = new Rect ();
drawables [0].CopyBounds (drawableBounds);
int leftOffset = ((Control.Width - Control.PaddingLeft - Control.PaddingRight) - drawableBounds.Width ()) / 2;
drawableBounds.Offset (leftOffset, 0);
drawables [0].SetBounds (drawableBounds.Left, drawableBounds.Top, drawableBounds.Right, drawableBounds.Bottom);
}
}
}
示例9: Draw
public override void Draw(Canvas canvas)
{
var box = Element as RoundedBox;
var rect = new Rect();
var paint = new Paint() {
Color = box.BackgroundColor.ToAndroid(),
AntiAlias = true,
};
GetDrawingRect(rect);
var radius = (float)(rect.Width() / box.Width * box.CornerRadius);
canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);
}
示例10: Draw
public override void Draw(Canvas canvas)
{
var box = Element as CustomRoundedBox;
var rect = new Rect();
var paint = new Paint
{
AntiAlias = true,
};
paint.SetARGB((int)box.BackgroundColor.A, (int)box.BackgroundColor.R, (int)box.BackgroundColor.G, (int)box.BackgroundColor.B);
GetDrawingRect(rect);
var radius = (float)(rect.Width() / box.Width * box.CornerRadius);
canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);
}
示例11: Draw
public override void Draw(Canvas canvas)
{
var box = Element as RoundedBox;
var rect = new Rect();
var androidColor = box.BackgroundColor.ToAndroid();
var paint = new Paint()
{
AntiAlias = true,
};
paint.SetARGB(Convert.ToInt32(box.Opacity * 255), (int)androidColor.R, (int)androidColor.G, (int)androidColor.B);
GetDrawingRect(rect);
var radius = (float)(rect.Width() / box.Width * box.CornerRadius);
canvas.DrawRoundRect(new RectF(rect), radius, radius, paint);
}
示例12: OnBoundsChange
protected override void OnBoundsChange (Rect bounds)
{
base.OnBoundsChange (bounds);
mRect.Set (margin, margin, bounds.Width () - margin, bounds.Height () - margin);
if (useGradientOverlay) {
var colors = new int[] { 0, 0, 0x20000000 };
var pos = new float[] { 0.0f, 0.7f, 1.0f };
RadialGradient vignette = new RadialGradient (mRect.CenterX (),
mRect.CenterY () * 1.0f / 0.7f,
mRect.CenterX () * 1.3f,
colors,
pos, Shader.TileMode.Clamp);
Matrix oval = new Matrix ();
oval.SetScale (1.0f, 0.7f);
vignette.SetLocalMatrix (oval);
paint.SetShader (new ComposeShader (bitmapShader, vignette, PorterDuff.Mode.SrcOver));
}
}
示例13: ButtonTextSize
public float ButtonTextSize(string text, double fontSize)
{
if (_button == null) {
_button = new global::Android.Widget.Button(Forms.Context);
// _button.SetPadding(10, _button.PaddingTop, 10, _button.PaddingBottom);
_button.SetPadding(0, _button.PaddingTop, 0, _button.PaddingBottom);
}
if (fontSize != 0)
{
_button.TextSize = (float)fontSize;
}
var widgetPadding = 8;
var bounds = new Rect();
_button.Text = text;
_button.Paint.GetTextBounds(text, 0, text.Length, bounds);
// Add two times the widgetPadding of 8 dp, because the button has this min size and than resize to the next multi of 8.
// http://developer.android.com/guide/practices/ui_guidelines/widget_design.html
return (float)Math.Ceiling((bounds.Width() / Resources.System.DisplayMetrics.Density + _button.PaddingLeft + _button.PaddingRight + 2 * widgetPadding) / 8) * 8;
}
示例14: OnCreateDialog
public override Dialog OnCreateDialog(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Begin building a new dialog.
var builder = new AlertDialog.Builder(Activity);
Rect displayRectangle = new Rect();
Window window = Activity.Window;
window.DecorView.GetWindowVisibleDisplayFrame(displayRectangle);
var inflater = Activity.LayoutInflater;
dateView = inflater.Inflate(Resource.Layout.DateRange, null);
dateView.SetMinimumHeight((int)(displayRectangle.Width() * 0.9f));
dateView.SetMinimumHeight((int)(displayRectangle.Height() * 0.9f));
Button butOk = dateView.FindViewById<Button> (Resource.Id.butok);
butOk.Click+= ButOk_Click;
datePicker1 = DatePicker.NewInstance(SetDateDlg1);
datePicker2 = DatePicker.NewInstance(SetDateDlg2);
EditText frd = dateView.FindViewById<EditText> (Resource.Id.trxdatefr);
EditText tod = dateView.FindViewById<EditText> (Resource.Id.trxdateto);
frd.Text = DateTime.Today.ToString ("dd-MM-yyyy");
frd.Click += delegate(object sender, EventArgs e) {
datePicker1.Show(FragmentManager, "datePicker");
};
tod.Text = DateTime.Today.ToString ("dd-MM-yyyy");
tod.Click += delegate(object sender, EventArgs e) {
datePicker2.Show(FragmentManager, "datePicker2");
};
builder.SetView (dateView);
builder.SetPositiveButton ("CANCEL", HandlePositiveButtonClick);
var dialog = builder.Create();
//Now return the constructed dialog to the calling activity
return dialog;
}
示例15: OnDraw
//Actual Draw of analogue niddle in Canvas which will show in watch surface
public override void OnDraw(Canvas canvas, Rect bounds)
{
time.SetToNow ();
int width = bounds.Width ();
int height = bounds.Height ();
// Draw the background, scaled to fit.
if (backgroundScaledBitmap == null
|| backgroundScaledBitmap.Width != width
|| backgroundScaledBitmap.Height != height) {
backgroundScaledBitmap = Bitmap.CreateScaledBitmap (backgroundBitmap,
width, height, true /* filter */);
}
canvas.DrawColor (Color.Black);
canvas.DrawBitmap (backgroundScaledBitmap, 0, 0, null);
float centerX = width / 2.0f;
float centerY = height / 2.0f;
// Draw the ticks.
float innerTickRadius = centerX - 10;
float outerTickRadius = centerX;
for (int tickIndex = 0; tickIndex < 12; tickIndex++) {
float tickRot = (float)(tickIndex * Math.PI * 2 / 12);
float innerX = (float)Math.Sin (tickRot) * innerTickRadius;
float innerY = (float)-Math.Cos (tickRot) * innerTickRadius;
float outerX = (float)Math.Sin (tickRot) * outerTickRadius;
float outerY = (float)-Math.Cos (tickRot) * outerTickRadius;
canvas.DrawLine (centerX + innerX, centerY + innerY,
centerX + outerX, centerY + outerY, tickPaint);
}
float secRot = time.Second / 30f * (float)Math.PI;
int minutes = time.Minute;
float minRot = minutes / 30f * (float)Math.PI;
float hrRot = ((time.Hour + (minutes / 60f)) / 6f) * (float)Math.PI;
float secLength = centerX - 20;
float minLength = centerX - 40;
float hrLength = centerX - 80;
if (!IsInAmbientMode) {
float secX = (float)Math.Sin (secRot) * secLength;
float secY = (float)-Math.Cos (secRot) * secLength;
canvas.DrawLine (centerX, centerY, centerX + secX, centerY + secY, secondPaint);
}
float minX = (float)Math.Sin (minRot) * minLength;
float minY = (float)-Math.Cos (minRot) * minLength;
canvas.DrawLine (centerX, centerY, centerX + minX, centerY + minY, minutePaint);
float hrX = (float)Math.Sin (hrRot) * hrLength;
float hrY = (float)-Math.Cos (hrRot) * hrLength;
canvas.DrawLine (centerX, centerY, centerX + hrX, centerY + hrY, hourPaint);
}