本文整理汇总了C#中Android.Graphics.Rect.Height方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Height方法的具体用法?C# Rect.Height怎么用?C# Rect.Height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Graphics.Rect
的用法示例。
在下文中一共展示了Rect.Height方法的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: 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;
}
示例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: MeasureString
//http://egoco.de/post/19077604048/calculating-the-height-of-text-in-android
//http://stackoverflow.com/questions/16082359/how-to-auto-adjust-text-size-on-a-multi-line-textview-according-to-the-view-max
public SizeF MeasureString(string text, int maxWidth = 2147483647)
{
TextPaint paint = AndroidBrush.CreateTextPaint();
paint.TextSize = SizeInPoints;
paint.SetTypeface(InnerFont);
int lineCount = 0;
int index = 0;
int length = text.Length;
float[] measuredWidths = new float[]{ 0 };
float measuredWidth = 1f;
while(index < length - 1)
{
index += paint.BreakText(text, index, length, true, maxWidth, measuredWidths);
lineCount++;
if (measuredWidth < measuredWidths[0]) measuredWidth = measuredWidths[0];
}
Rect bounds = new Rect();
paint.GetTextBounds("Py", 0, 2, bounds);
float height = (float)System.Math.Floor((double)lineCount * bounds.Height());
return new SizeF (measuredWidth, height);
}
示例5: 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);
}
}
示例6: OnBoundsChange
protected override void OnBoundsChange (Rect bounds)
{
base.OnBoundsChange (bounds);
if (oval == null)
return;
oval.Set (0, 0, bounds.Width (), bounds.Height ());
}
示例7: 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);
}
示例8: Draw
public override void Draw(Canvas canvas)
{
Rect bounds = Bounds;
int height = bounds.Height();
paint.TextSize = height;
Rect textBounds = new Rect();
string textValue = icon.Character.ToString();
paint.GetTextBounds(textValue, 0, 1, textBounds);
int textHeight = textBounds.Height();
float textBottom = bounds.Top + (height - textHeight) / 2f + textHeight - textBounds.Bottom;
canvas.DrawText(textValue, bounds.ExactCenterX(), textBottom, paint);
}
示例9: 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();
}
示例10: 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));
}
}
示例11: 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;
}
示例12: OnDraw
public override void OnDraw(Canvas canvas, Rect bounds)
{
if (Log.IsLoggable (Tag, LogPriority.Debug)) {
Log.Debug (Tag, "onDraw");
}
long now = Java.Lang.JavaSystem.CurrentTimeMillis ();
time.Set (now);
int milliseconds = (int)(now % 1000);
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 seconds = time.Second + milliseconds / 1000f;
float secRot = seconds / 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);
if (IsVisible && !IsInAmbientMode) {
Invalidate ();
}
}
示例13: MeasureText
public BasicRectangle MeasureText(string text, BasicRectangle rectangle, string fontFace, float fontSize)
{
var paint = new Paint
{
AntiAlias = true,
TextSize = fontSize * Density
};
var rectText = new Rect();
paint.GetTextBounds(text, 0, text.Length, rectText);
return new BasicRectangle(rectText.Left, rectText.Top, rectText.Width(), rectText.Height());
}
示例14: DrawHands
void DrawHands(Canvas canvas, Rect bounds)
{
var width = bounds.Width();
var height = bounds.Height();
var centerX = width / 2.0f;
var centerY = height / 2.0f;
calendar.TimeInMillis = Java.Lang.JavaSystem.CurrentTimeMillis();
var hour = calendar.Get(CalendarField.Hour);
var minute = calendar.Get(CalendarField.Minute);
var second = calendar.Get(CalendarField.Second);
var secRot = second / 30f * (float)Math.PI;
var minutes = minute;
var minRot = minutes / 30f * (float)Math.PI;
var hrRot = ((hour + (minutes / 60f)) / 6f) * (float)Math.PI;
var secLength = centerX - 20;
var minLength = centerX - 40;
var hrLength = centerX - 80;
if (!IsInAmbientMode)
{
var secX = (float)Math.Sin(secRot) * secLength;
var secY = (float)-Math.Cos(secRot) * secLength;
canvas.DrawLine(centerX, centerY, centerX + secX, centerY + secY, secondPaint);
}
var minX = (float)Math.Sin(minRot) * minLength;
var minY = (float)-Math.Cos(minRot) * minLength;
canvas.DrawLine(centerX, centerY, centerX + minX, centerY + minY, minutePaint);
var hrX = (float)Math.Sin(hrRot) * hrLength;
var hrY = (float)-Math.Cos(hrRot) * hrLength;
canvas.DrawLine(centerX, centerY, centerX + hrX, centerY + hrY, hourPaint);
}
示例15: DrawFace
void DrawFace(Canvas canvas, Rect bounds)
{
var width = bounds.Width();
var 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);
var centerX = width / 2.0f;
var centerY = height / 2.0f;
// Draw the ticks.
var innerTickRadius = centerX - 10;
var outerTickRadius = centerX;
for (var tickIndex = 0; tickIndex < 12; tickIndex++)
{
var tickRot = (float)(tickIndex * Math.PI * 2 / 12);
var innerX = (float)Math.Sin(tickRot) * innerTickRadius;
var innerY = (float)-Math.Cos(tickRot) * innerTickRadius;
var outerX = (float)Math.Sin(tickRot) * outerTickRadius;
var outerY = (float)-Math.Cos(tickRot) * outerTickRadius;
canvas.DrawLine(centerX + innerX, centerY + innerY,
centerX + outerX, centerY + outerY, tickPaint);
}
}