在这里,我已经延长从View类TransparentCircleView类,但我无法使用该视图在.axml文件。给错误错误解析XML:没有很好地形成(标记无效)FieldStar.Droid E:\项目\ FieldStar \ FieldStar.Droid \资源\布局\ activity_home.axml 44
透明圈View.ca
namespace FieldStar.Droid.Views
{
[Register("FieldStar/Droid/Views/TransparentCircleView")]
public class TransparentCircleView : View
{
private readonly string DEFAULT_BACKGROUND_COLOR = "#ffffff";
private readonly string DEFAULT_FOREGROUND_COLOR = "#000000";
private Paint _backgroundPaint, _foregroundPaint;
public TransparentCircleView(Context context) : base(context)
{
Init();
}
public TransparentCircleView(Context context, IAttributeSet attrs) : base(context, attrs)
{
Init();
}
public TransparentCircleView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
{
Init();
}
public TransparentCircleView(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
{
Init();
}
protected TransparentCircleView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
int radius = -1;
if (Width < Height)
{
radius = (Width - PaddingLeft - PaddingRight) / 2;
}
else
{
radius = (Height - PaddingTop - PaddingBottom) / 2;
}
//Background Circle
canvas.DrawRect(0, 0, Width, Height, _backgroundPaint);
//Foreground Circle
canvas.DrawCircle(Width / 2, Height / 2, radius,_foregroundPaint);
}
private void Init()
{
_backgroundPaint = new Paint();
_backgroundPaint.AntiAlias = true;
_backgroundPaint.SetStyle(Paint.Style.Fill);
_backgroundPaint.Color = Color.ParseColor(DEFAULT_BACKGROUND_COLOR);
//Foreground View
_foregroundPaint = new Paint();
_foregroundPaint.AntiAlias = true;
_foregroundPaint.SetStyle(Paint.Style.Fill);
_foregroundPaint.Color = Resources.GetColor(Android.Resource.Color.Transparent);
}
public void SetBackgroundColor(string color)
{
_backgroundPaint.Color = Color.ParseColor(color);
Invalidate();
}
public void SetForegroundColor(string color)
{
_foregroundPaint.Color = Color.ParseColor(color);
Invalidate();
}
}
}
这个错误的最常见原因是没有保证的命名空间路径组件是小写。你说,错误返回的事实是“错误错误解析XML:没有很好地形成(标记无效)FieldStar.Droid”往往指向这个作为的问题。请确保您在XML引用组件,如下所示:
<fieldStar.droid.views.TransparentCircleView
.....
.....
/>