Forum Xamarin.Android

Get shape programmatically

I want to create candlestick chart with 500 items (rectangles).
I must change color and size of items when scrolling. I think to use 500 View inside ScollView.

How I can get shape for draw my views programmatically?

public class CustomBorderRedDrawable : Android.Graphics.Drawables.ShapeDrawable 
    private Paint fillpaint, strokepaint;
    private static int WIDTH = 3;

    public CustomBorderRedDrawable(Android.Graphics.Drawables.Shapes.Shape s) {

        fillpaint = new Paint();
        fillpaint.StrokeWidth = 10;
        fillpaint.Color = Color.Red;  

        strokepaint = new Paint();
        strokepaint.StrokeWidth = WIDTH;
        strokepaint.Color = Color.ParseColor("#008000");        

    protected override void OnDraw(Android.Graphics.Drawables.Shapes.Shape shape, Canvas canvas, Paint fillpaint) {
        shape.Draw(canvas, fillpaint);
        shape.Draw(canvas, strokepaint);

    public void setFillColour(int c){
        fillpaint.Color = Color.Transparent;

public class MainActivity : Activity
    protected override void OnCreate(Bundle bundle)
       View view = new View(context);
       CustomBorderDrawable drawable = new CustomBorderDrawable(???);


Best Answer


Sign In or Register to comment.