[英]How to draw a Graphics ? - xamarin
我試圖在我的布局中間創建一個圖形,可以在Linearlayout中對其進行限制。 示例=> 打印應用程序這是我的應用程序,圖形必須位於白色區域,寫為“ Diagram”。
圖形只需要直線和貝塞爾曲線。
實際上,我不知道它是否具有可以繪制的特定對象。 與線(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);
}
}
如何在布局的特定位置繪制此圖形?
如何在布局的特定位置繪制此圖形?
完成繪制視圖MyView
,可以將其放置在xml中的布局中,例如:
<YOURNAMESPACE.MyView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/myview" />
在這種情況下,它可以像布局中的普通UI組件一樣使用,這意味着您可以在特定位置放置Margin
, Gravity
等布局參數。
如果要在后面的代碼中實現它,可以使用LayoutParams 。 具體的布局代碼取決於您使用的父視圖。
基本上,這意味着您可以在View
的子類中使用Paint
View
,並將其像UI組件一樣放置在布局中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.