Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Custom GridLayout

A have a custom GridLayout class:
`using System;
using Android.Widget;
using Android.Content;
using Android.Graphics;

namespace SUDOKU
public class GridLayoutExt:GridLayout
public GridLayoutExt (Context context):base(context)
SetWillNotDraw (false);

    protected override void OnDraw(Canvas canvas)
        base.OnDraw (canvas);

        Paint paint = new Paint ();
        paint.Color = Android.Graphics.Color.Red;
        paint.StrokeWidth = 4;

        canvas.DrawLine (0, 0, 100, 100, paint);



How can I add it to the screen of my application&

When I'm trying to start application I have an exception:

In this place:
GridLayoutExt GL = new GridLayoutExt (this); GL.ColumnCount = ColNum; **GL.LayoutParameters.Width = getWidth();** GL.LayoutParameters.Height = getWidth();

Here is the getWidth() method:

`public int getWidth()
int widthInP;
var metrics = Resources.DisplayMetrics;
widthInP = metrics.WidthPixels;//ConvertPixelsToDp(metrics.WidthPixels);

        return widthInP;

How can I resolve this problem?
Thank you for help!



  • PaimaPaima RUMember
    edited August 2015

    May be some body have another way to solve my problem?
    How can I draw lines above my gridlayout?
    Thank you!

Sign In or Register to comment.