请问为什么 void 对于变量 onDraw 是无效类型 protected void onDraw(Canvas canvas)代码如下
publicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setCo...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new Myview(this));
}
private class Myview extends View{
public Myview (Context context) {
super(context);
@Override
protected void onDraw (Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.DKGRAY);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
canvas.drawPoint(5,5,paint);
}
}
} 展开
super.onCreate(savedInstanceState);
setContentView(new Myview(this));
}
private class Myview extends View{
public Myview (Context context) {
super(context);
@Override
protected void onDraw (Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.DKGRAY);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
canvas.drawPoint(5,5,paint);
}
}
} 展开
2个回答
展开全部
请不要在构造函数里面 定义方法
方法应该定义在 class 级别下
改成这样:
private class Myview extends View{
public Myview (Context context) {
super(context);
}
@Override
protected void onDraw (Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.DKGRAY);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
canvas.drawPoint(5,5,paint);
}
}
方法应该定义在 class 级别下
改成这样:
private class Myview extends View{
public Myview (Context context) {
super(context);
}
@Override
protected void onDraw (Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.DKGRAY);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
canvas.drawPoint(5,5,paint);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询