简体   繁体   English

如何绘制图形? -Xamarin

[英]How to draw a Graphics ? - xamarin

I am trying to create a graphic in the middle of my layout, which can be restricted in a Linearlayout. 我试图在我的布局中间创建一个图形,可以在Linearlayout中对其进行限制。 Example => Print App This is my application and the graphic has to be in the white area written "Diagram". 示例=> 打印应用程序这是我的应用程序,图形必须位于白色区域,写为“ Diagram”。

The graphic only needs lines and bezier curves. 图形只需要直线和贝塞尔曲线。

in fact I do not know if it has a specific object where I can draw. 实际上,我不知道它是否具有可以绘制的特定对象。 with lines (x1, y1, x2, y2). 与线(x1,y1,x2,y2)。

public class MyView : View
{
    protected override void OnDraw(Canvas canvas)
    {
        base.OnDraw(canvas);
        Paint green = new Paint {
            AntiAlias = true,
            Color = Color.Rgb(0x99, 0xcc, 0),
        };
        green.SetStyle(Paint.Style.FillAndStroke);

        Paint red = new Paint {
            AntiAlias = true,
            Color = Color.Rgb(0xff, 0x44, 0x44)
        };
        red.SetStyle(Paint.Style.FillAndStroke);

        float middle = canvas.Width * 0.25f;
        canvas.DrawPaint(red);
        canvas.DrawRect(0, 0, middle, canvas.Height, green);
    }
}

How do I draw this in a specific place in my layout? 如何在布局的特定位置绘制此图形?

How do I draw this in a specific place in my layout? 如何在布局的特定位置绘制此图形?

After you've complete your draw view MyView , you can place it in your layout in xml for example like this: 完成绘制视图MyView ,可以将其放置在xml中的布局中,例如:

<YOURNAMESPACE.MyView android:layout_height="wrap_content"
                      android:layout_width="wrap_content"
                      android:id="@+id/myview" />

In this case, it can be used like normal UI components in the layout, means you can use Margin , Gravity and such layout parameters to certain the location where it should be placed. 在这种情况下,它可以像布局中的普通UI组件一样使用,这意味着您可以在特定位置放置MarginGravity等布局参数。

If you want to implement it in the code behind, you can use LayoutParams . 如果要在后面的代码中实现它,可以使用LayoutParams Specific layout code depends on which parent view are you using. 具体的布局代码取决于您使用的父视图。

Basically it means, you can draw the view use Paint in the subclass of View and place it like a UI components in your layout. 基本上,这意味着您可以在View的子类中使用Paint View ,并将其像UI组件一样放置在布局中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM