Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin.android Xamarin Android自定义视图未加载_Xamarin.android_Xamarin - Fatal编程技术网

Xamarin.android Xamarin Android自定义视图未加载

Xamarin.android Xamarin Android自定义视图未加载,xamarin.android,xamarin,Xamarin.android,Xamarin,我是Xamarin monoandroid的新手,在向布局中添加自定义视图时遇到了一个问题。我不知道我做错了什么。这是我的自定义视图类 调用了onDraw方法,但我没有得到输出,也没有错误 类位置抽屉:视图 { 私人整数计数; 私人职位; 私人IPositionDrawer cinterface; 私人活动效率; 私人集装箱; 私人INTP; 私人ScoreFeed scoreFeed1; 私人ScoreFeed scoreFeed2; 公共位置抽屉(活动上下文、整数计数、整数定位器、活动活动活

我是Xamarin monoandroid的新手,在向布局中添加自定义视图时遇到了一个问题。我不知道我做错了什么。这是我的自定义视图类

调用了onDraw方法,但我没有得到输出,也没有错误

类位置抽屉:视图
{
私人整数计数;
私人职位;
私人IPositionDrawer cinterface;
私人活动效率;
私人集装箱;
私人INTP;
私人ScoreFeed scoreFeed1;
私人ScoreFeed scoreFeed2;
公共位置抽屉(活动上下文、整数计数、整数定位器、活动活动活动):
基础(上下文)
{
//初始化();
this.cactivity=cactivity;
this.cinterface=cinterface;
this.count=计数;
该位置=定位器;
//这个;
初始化();
}
私有void初始化()
{
//这个。使无效();
//此.设置的测量尺寸(100100);
此.SetWillNotDraw(false);
Console.WriteLine(this.WillNotDraw());
}
测量时受保护的覆盖无效(int-widthMeasureSpec、int-heightMeasureSpec)
{
测量基础(宽度测量等级、高度测量等级);
}
公共无效设置抽屉(整数计数、整数定位器、活动活动能力)
{
this.cactivity=cactivity;
this.cinterface=cinterface;
this.count=计数;
该位置=定位器;
//碱(活性);
}
受保护的覆盖无效OnDraw(画布)
{
底座.OnDraw(帆布);
蓝色油漆=新油漆();
蓝色。颜色=颜色。红色;
float screenwidth=cactivity.WindowManager.DefaultDisplay.Width;
canvas.DrawRect(屏幕宽度*位置-1,0,屏幕宽度*位置,20,蓝色);
控制台写入线(“SW1:+屏幕宽度+”位置1:+位置);
//LinearLayout can=cactivity.FindViewById(容器);
//cinterface.getview(this);
}
}
我使用以下代码将视图添加到布局中

 View pd = new PositionDrawer(this, 3, position, this);
 container = FindViewById<LinearLayout>(Resource.Id.position);
 container.RemoveAllViews();
 container.AddView(pd);
View pd=新位置抽屉(this,3,position,this);
container=findviewbyd(Resource.Id.position);
container.removeallview();
container.AddView(pd);

提前谢谢

您需要实现正确的CTOR

当您实现
视图
类时,您必须至少拥有具有以下签名的ctor:

public PositionDrawer(IntPtr javaReference, JniHandleOwnership transfer)
    : base(javaReference, transfer) { }
public PositionDrawer(Context context, IAttributeSet attrs, int defStyle)
    : base(context, attrs, defStyle)
如果在
AXML
布局中使用
视图
,则还需要具有以下签名的视图:

public PositionDrawer(IntPtr javaReference, JniHandleOwnership transfer)
    : base(javaReference, transfer) { }
public PositionDrawer(Context context, IAttributeSet attrs, int defStyle)
    : base(context, attrs, defStyle)

否则,当您从代码创建
视图
s时,您需要给它们一些
布局参数
,否则它们不知道自己的大小。

我已经添加了带签名的ctor。但是我不知道如何初始化这个类。一个例子就是帮助。