当前位置: 首页>>代码示例>>C#>>正文


C# Android.DrawRect方法代码示例

本文整理汇总了C#中Android.DrawRect方法的典型用法代码示例。如果您正苦于以下问题:C# Android.DrawRect方法的具体用法?C# Android.DrawRect怎么用?C# Android.DrawRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android的用法示例。


在下文中一共展示了Android.DrawRect方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnDraw

        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            var rect = new RectF(0, 0, 300, 300);
            switch (Shape)
            {
                case Shape.Circle:
                    canvas.DrawOval(rect, new Paint() { Color = Color.CornflowerBlue });
                    break;
                case Shape.Square:
                    canvas.DrawRect(rect, new Paint() { Color = Color.Crimson });
                    break;
                case Shape.Triangle:

                    var path = new Path();
                    path.MoveTo(rect.CenterX(), rect.Top);
                    path.LineTo(rect.Left, rect.Bottom);
                    path.LineTo(rect.Right, rect.Bottom);
                    path.Close();
                    var paint = new Paint() {Color = Color.Crimson};
                    paint.Color = Color.Gold;
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawPath(path, paint);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:Coolerhino,项目名称:MvvmCross-Tutorials,代码行数:27,代码来源:ShapeView.cs

示例2: Draw

        public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw(canvas);

            var rect = new RectF(0,0,300,300);
            switch (TheShape)
            {
                case Shape.Circle:
                    canvas.DrawOval(rect, new Paint() { Color = Color.Aqua });
                    break;
                case Shape.Square:
                    canvas.DrawRect(rect, new Paint() { Color = Color.Red });
                    break;
                case Shape.Triangle:
                    var path = new Path();
                    path.MoveTo(rect.CenterX(), 0);
                    path.LineTo(0, rect.Height());
                    path.LineTo(rect.Width(), rect.Height());
                    path.Close();

                    var paint = new Paint() {Color = Color.Magenta};
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawPath(path, paint);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:KiranKumarAlugonda,项目名称:NPlus1DaysOfMvvmCross,代码行数:29,代码来源:CustomDrawShapeView.cs

示例3: OnDraw

        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            String rdText = this.Text.ToString();
            Paint textPaint = new Paint();
            textPaint.AntiAlias = true;
            textPaint.TextSize = this.TextSize;
            textPaint.TextAlign = Android.Graphics.Paint.Align.Center;

            float canvasWidth = canvas.Width;
            float textWidth = textPaint.MeasureText(rdText);

            if (Checked)
            {
                this.SetBackgroundResource(Resource.Drawable.RoundedShape);
                int[] colors = new int[] { this.Context.Resources.GetColor(Resource.Color.radioUnselectTop), this.Context.Resources.GetColor(Resource.Color.radioSelectTop )};
                GradientDrawable grad = new GradientDrawable(GradientDrawable.Orientation.TopBottom, colors);
                grad.SetBounds(0, 0, this.Width, this.Height);
                grad.SetCornerRadius(7f);
                this.SetBackgroundDrawable(grad);
            }
            else
            {
                this.SetBackgroundResource(Resource.Drawable.RoundedShape);
                int[] colors = new int[] { this.Context.Resources.GetColor(Resource.Color.radioUnselectTop), this.Context.Resources.GetColor(Resource.Color.radioUnselectBottom) };
                GradientDrawable grad = new GradientDrawable(GradientDrawable.Orientation.TopBottom, colors);
                grad.SetBounds(0, 0, this.Width, this.Height);
                grad.SetCornerRadius(7f);
                this.SetBackgroundDrawable(grad);
            }

            Paint paint = new Paint();
            paint.Color = Color.Transparent;
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            Rect rect = new Rect(0, 0, this.Width, this.Height);
            canvas.DrawRect(rect, paint);

            base.OnDraw(canvas);
        }
开发者ID:gsoldav,项目名称:Android-Xamarin,代码行数:38,代码来源:RadioButtonExtended.cs

示例4: OnDraw

		protected override void OnDraw (Android.Graphics.Canvas canvas)
		{
			int height = Height;
			int childCount = ChildCount;
			int dividerHeightPx = (int) (Math.Min(Math.Max(0f, _dividerHeight), 1f) * height);
			SlidingTabLayout.ITabColorizer tabColorizer =_customTabColorizer != null ? _customTabColorizer: _defaultTabColorizer;

			// Thick colored underline below the current selection
			if (childCount > 0) {
				View selectedTitle = GetChildAt(_selectedPosition);
				int left = selectedTitle.Left;
				int right = selectedTitle.Right;
				int color = tabColorizer.GetIndicatorColor(_selectedPosition);

				if (_selectionOffset > 0f && _selectedPosition < (ChildCount - 1)) {
					int nextColor = tabColorizer.GetIndicatorColor(_selectedPosition + 1);
					if (color != nextColor) {
						color = BlendColors(nextColor, color, _selectionOffset);
					}

					// Draw the selection partway between the tabs
					View nextTitle = GetChildAt(_selectedPosition + 1);
					left = (int) (_selectionOffset * nextTitle.Left +(1.0f - _selectionOffset) * left);
					right = (int) (_selectionOffset * nextTitle.Right +(1.0f - _selectionOffset) * right);
				}
					
				_selectedIndicatorPaint.Color = Color.LightSkyBlue;


				canvas.DrawRect(left, height - _selectedIndicatorThickness, right,
					height, _selectedIndicatorPaint);
			}

			// Thin underline along the entire bottom edge
			canvas.DrawRect(0, height - _bottomBorderThickness, Width, height, _bottomBorderPaint);

			// Vertical separators between the titles
			int separatorTop = (height - dividerHeightPx) / 2;
			for (int i = 0; i < childCount - 1; i++) {
				View child = GetChildAt(i);
				_dividerPaint.Color=Color.Gray;
				canvas.DrawLine(child.Right, separatorTop, child.Right,
					separatorTop + dividerHeightPx, _dividerPaint);
			}
		}
开发者ID:jeedey93,项目名称:xamarin-android-samples,代码行数:45,代码来源:SlidingTabStrip.cs

示例5: DispatchDraw

        protected override void DispatchDraw(Android.Graphics.Canvas canvas)
        {
            base.DispatchDraw (canvas);

            if (opened || isTracking || animator != null) {
                // Draw inset shadow on the menu
                canvas.Save ();
                shadowDrawable.SetBounds (0, 0, Context.ToPixels (8), Height);
                canvas.Translate (ContentView.Left - shadowDrawable.Bounds.Width (), 0);
                shadowDrawable.Draw (canvas);
                canvas.Restore ();

                if (contentOffsetX != 0) {
                    // Cover the area with a black overlay to display openess graphically
                    var openness = ((float)(MaxOffset - contentOffsetX)) / MaxOffset;
                    overlayPaint.Alpha = Math.Max (0, (int)(MaxOverlayAlpha * openness));
                    if (overlayPaint.Alpha > 0)
                        canvas.DrawRect (0, 0, ContentView.Left, Height, overlayPaint);
                }
            }
        }
开发者ID:howsgame,项目名称:howsgame,代码行数:21,代码来源:FlyOutContainer.cs

示例6: OnDraw

        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            // On draw or redraw, we should
            // get our cached bitmap
            Bitmap gameTargetBitmap = GetBitmapFromMemCache("target");

            // For multiple dragging object, but for
            // now we only have one. :)
            foreach (DragObject dObject in dragObjects) {

                #region Draw transparent target area
                paint.SetStyle(Paint.Style.Fill);
                // Set tranparent paint
                // Change this to another ARGB color to
                // see the target area
                paint.SetARGB(128, 255, 255, 255);

                // Coords for target drop area
                const int x1 = 767;
                const int x2 = 990;
                const int y1 = 204;
                const int y2 = 560;

                // Draw target area
                canvas.DrawRect(x1, y1, x2, y2, paint);

                // Set target drop area for our check if the
                // dragged object is within the drop area bounds
                this.targetDropX1 = x1;
                this.targetDropX2 = x2;
                this.targetDropY1 = y1;
                this.targetDropY2 = y2;

                // Offset the bitmap overlay just a
                // bit to look nice
                const int xOffset = 10;
                const int yOffset = 10;

                // Draw target bitmap overlay
                canvas.DrawBitmap(gameTargetBitmap, targetDropX1 + xOffset, targetDropY1 + yOffset, null);
                #endregion Draw transparent target area with a image overlay

                // Draw object bitmap to drag
                canvas.DrawBitmap(dObject.GetBitmap(), dObject.GetX(), dObject.GetY(), null);
            }
        }
开发者ID:rondelrosario,项目名称:DragAndDrop,代码行数:46,代码来源:DrawView.cs

示例7: OnDraw

        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            if (mixerValue == null) // don't do anything if we're not connected to a mixervalue
                return;

            if (bmp == null) {
                bmp = BitmapFactory.DecodeResource (Resources, Resource.Drawable.Fader_Knob);
                Bitmap scaled = Bitmap.CreateScaledBitmap (bmp, 25, 55, true);
                bmp.Recycle();
                bmp = scaled;
            }

            int margin = 60;
            float radius = 4;
            int center = (Width / 2) + 5;
            int minY1 = margin - (bmp.Height / 2);
            int maxY1 = Height - margin - (bmp.Height / 2);
            rangeY = maxY1 - minY1;
            float factor = (float)mixerValue.GetValue() / (float)maxValue;

            bitmapX1 = center - bmp.Width / 2;
            bitmapY1 = maxY1 - (int)(factor * (float)rangeY);

            base.OnDraw (canvas);

            var paint = new Paint ();
            paint.Color = Color.White;
            paint.TextAlign = Paint.Align.Center;
            paint.TextSize = (float)12.0;
            paint.SetTypeface(Typeface.DefaultBold);

            if (channel_name != null)
                canvas.DrawText (channel_name, center - 5, 14, paint); // align with pan control

            int levelX1 = center - (bmp.Width / 2) - 2;
            int levelX2 = center + (bmp.Width / 2);

            paint.TextSize = (float)10.0;
            paint.TextAlign = Paint.Align.Right;

            foreach (var level in faderLevels) {
                float factorLevel = (float)level.Key / (float)maxValue;
                int levelY = maxY1 - (int)(factorLevel * (float)rangeY) + (bmp.Height / 2);

                canvas.DrawRect (levelX1, levelY - 1, levelX2, levelY, paint);
                canvas.DrawText (level.Value, levelX1 - 4, levelY + 3, paint);
            }

            paint.Color = Color.DarkGray;
            RectF rect = new RectF (center - 2, margin, center + 2, Height - margin);
            canvas.DrawRoundRect(rect, radius, radius, paint);
            paint.Color = Color.Black;
            rect = new RectF (center - 1, margin + 1, center + 1, Height - margin - 1);
            canvas.DrawRoundRect(rect, radius, radius, paint);

            bitmapX2 = bitmapX1 + bmp.Width;
            bitmapY2 = bitmapY1 + bmp.Height;

            if (isActive) {
                paint.Alpha = 255;
            } else {
                paint.Alpha = 180;
            }

            canvas.DrawBitmap (bmp, bitmapX1, bitmapY1, paint);

            //bmp.Recycle ();
        }
开发者ID:GeorgeWieggers,项目名称:QuMixDroid_xamarin,代码行数:68,代码来源:Fader.cs

示例8: Draw

            public override void Draw(Android.Graphics.Canvas canvas)
            {
                if (Control == null) return;

                Control.CreateGraphicBuffers();

                var ctime = System.Environment.TickCount;
                Fleux.UIElements.Canvas.drawtime = 0;

                if (Control.offUpdated)
                {
                    lock(Control.offBmp)
                    {

                        Control.Draw(new PaintEventArgs(Control.offGr, new Rectangle(0,0, Control.offBmp.Width, Control.offBmp.Height)));

                        updcnt++;
                    }
                }
                Control.offUpdated = false;

                lock(Control.offBmp)
                {
                    if (Fleux.Core.FleuxApplication.HorizontalMirror)
                    {
                        canvas.Save();
                        canvas.Scale (-1, 1);
                        canvas.Translate (-(float)Control.drect.Width(), 0);
                    }else if (Fleux.Core.FleuxApplication.VerticalMirror)
                    {
                        canvas.Save();
                        canvas.Scale (1, -1);
                        canvas.Translate (0, -(float)Control.drect.Height());
                    }

                    Control.offGr.Flush();

                    canvas.DrawBitmap(Control.offBmp.ABitmap, Control.srect, Control.drect, paint);

                    updcntflush++;
                }
                if (PerfData)
                {
                    ctime = System.Environment.TickCount - ctime;
                    {
                        totime += ctime;
                    }
                    var cavg = totime / (updcnt+1);

                    var cpaint = new Android.Graphics.Paint();
                    cpaint.Color = new Android.Graphics.Color(0xA0, 0xFF, 0xFF, 0xFF);
                    cpaint.SetStyle(Android.Graphics.Paint.Style.Fill);
                    canvas.DrawRect(0,0, 250, 20, cpaint);
                    canvas.DrawText(""+updcnt+":"+updcntflush+":"+updcntinval+" ctime: "+ctime+"cavg:"+cavg+" canv: "+Fleux.UIElements.Canvas.drawtime, 0,20, spaint);
                    cpaint.Dispose();
                    if (updcnt > 100)
                    {
                        totime = 0;
                        updcnt = 0;
                    }
                }
            }
开发者ID:cail,项目名称:fleux,代码行数:62,代码来源:DoubleBufferedControl.cs

示例9: Draw

    public override void Draw (Android.Graphics.Canvas canvas, MapView mapView, bool shadow)
    {
        base.Draw (canvas, mapView, shadow);
 
        var paint = new Paint ();
        paint.AntiAlias = true;
        paint.Color = Color.Purple;
 
        // to draw fixed graphics that will not move or scale with the map
        //canvas.DrawRect (0, 0, 100, 100, paint);
 
        // to draw graphics at a geocoded location that move and scale with the map
        var gp = new GeoPoint ((int)41.940542E6, (int)-73.363447E6);     
        var pt = mapView.Projection.ToPixels (gp, null);     
        float distance = mapView.Projection.MetersToEquatorPixels (20000);
 
        canvas.DrawRect (pt.X, pt.Y, pt.X + distance, pt.Y + distance, paint);       
    }
开发者ID:89sos98,项目名称:monodroid-samples,代码行数:18,代码来源:MapWithOverlayActivity.cs

示例10: Draw

            public override void Draw(Android.Graphics.Canvas canvas)
            {
                if (Control == null) return;

                Control.CreateGraphicBuffers();

                if (origMatrix == null)
                {
                    origMatrix = new Android.Graphics.Matrix();
                    origMatrix.Set (canvas.Matrix);
                }
                if (hMatrix == null)
                {
                    hMatrix = new Android.Graphics.Matrix();
                    hMatrix.Set(origMatrix);
                    hMatrix.PostTranslate(-Control.offBmp.Width, 0);
                    hMatrix.PostScale(-1, 1);
                }
                if (vMatrix == null)
                {
                    vMatrix = new Android.Graphics.Matrix();
                    vMatrix.Set(origMatrix);
                    vMatrix.PostTranslate(0, -Control.offBmp.Height);
                    vMatrix.PostScale(1, -1);
                }

                var ctime = System.Environment.TickCount;
                var realupdate = false;
                Fleux.UIElements.Canvas.drawtime = 0;
                /**/
                if (Control.offNeedExtraDraw && Control.offUpdated)
                lock(Control.offBmp){
                    Control.offNeedExtraDraw = false;
                    Control.offUpdated = false;

                    Control.offBmpDraw = true;
                    Control.Draw(new PaintEventArgs(Control.offGr, new Rectangle(0,0, Control.offBmp.Width, Control.offBmp.Height)));
                    Control.offBmpDraw = false;

                    updcnt++;
                    realupdate = true;
                }
                //*/
                lock(Control.offBmp)
                {
                    if (Fleux.Core.FleuxApplication.HorizontalMirror)
                    {
                        canvas.Matrix = hMatrix;
                    }else if (Fleux.Core.FleuxApplication.VerticalMirror)
                    {
                        canvas.Matrix = vMatrix;
                    }else
                        canvas.Matrix = origMatrix;

                    // Thats for FastGraphics.cs
                    Control.offGr.Flush();

                    canvas.DrawBitmap(Control.offBmp.ABitmap, 0,0, paint);
                    Control.offUpdated = false;
                    updcntflush++;
                }
                if (PerfData)
                {
                    ctime = System.Environment.TickCount - ctime;
                    //if (realupdate)
                    {
                        totime += ctime;
                    }
                    var cavg = totime / (updcnt+1);

                    var cpaint = new Android.Graphics.Paint();
                    cpaint.Color = new Android.Graphics.Color(0xA0, 0xFF, 0xFF, 0xFF);
                    cpaint.SetStyle(Android.Graphics.Paint.Style.Fill);
                    canvas.DrawRect(0,0, 250, 20, cpaint);
                    canvas.DrawText(""+updcnt+":"+updcntflush+":"+updcntinval+" ctime: "+ctime+"cavg:"+cavg+" canv: "+Fleux.UIElements.Canvas.drawtime, 0,20, spaint);
                    cpaint.Dispose();
                    if (updcnt > 100)
                    {
                        totime = 0;
                        updcnt = 0;
                    }
                }
            }
开发者ID:flts,项目名称:fleux,代码行数:83,代码来源:DoubleBufferedControl.cs

示例11: OnDraw

        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            base.OnDraw(canvas);

            // Fill the background
            canvas.DrawPaint(mBackgroundPaint);

            // Test Text
            canvas.Save();
            var textWidth = mTextPaint.MeasureText("Hello");
            Rect textBounds = new Rect();
            mTextPaint.GetTextBounds("Hello", 0, 1, textBounds);
            canvas.DrawText("Hello", canvas.Width/2-textWidth/2, canvas.Height/2 - textBounds.Height()/2, mTextPaint);

            textWidth = mTextPaint.MeasureText("World");
            textBounds = new Rect();
            mTextPaint.GetTextBounds("World", 0, 1, textBounds);
            mTextPaint.Color = Color.Green;
            canvas.DrawText("World", (canvas.Width/2-textWidth/2) +100, (canvas.Height/2 - textBounds.Height()/2) + 100, mTextPaint);

            canvas.Restore();

            foreach (Box box in mBoxes) {
                float left = Math.Min(box.Origin.X, box.Current.X);
                float right = Math.Max(box.Origin.X, box.Current.X);
                float top = Math.Min(box.Origin.Y, box.Current.Y);
                float bottom = Math.Max(box.Origin.Y, box.Current.Y);
                canvas.Save();
                canvas.Rotate(box.Rotation, (box.Origin.X + box.Current.X)/2, (box.Origin.Y + box.Current.Y)/2 );
                canvas.DrawRect(left, top, right, bottom, mBoxPaint);
                canvas.Restore();
            }
        }
开发者ID:yingfangdu,项目名称:BNR,代码行数:33,代码来源:BoxDrawingView.cs

示例12: DoDraw

 public void DoDraw(Android.Graphics.Canvas canvas)
 {
     canvas.DrawRect(0f,_offset,100,_offset+100,rectPaint);
 }
开发者ID:PVoLan,项目名称:TestAndroidGame,代码行数:4,代码来源:TestGameFieldLogic.cs


注:本文中的Android.DrawRect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。