无法重写 onMeasure 方法
我需要重写 onMeasure
方法,但在尝试重写时出现错误: DrawLnClass.DrawLn 类型的方法 OnMeasure(int, int) 必须重写超类方法
这是我的代码:
public class DrawLnClass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new DrawLn(this));
}
public class DrawLn extends View {
Paint _paint;
int _height;
int _width;
Bitmap _bitmap;
Canvas _canvas;
Point[] xLine;
Point[] yLine;
public DrawLn(Context context) {
super(context);
_paint = new Paint();
_paint.setColor(Color.CYAN);
_paint.setStyle(Paint.Style.STROKE);
}
@Override
protected void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
_width = View.MeasureSpec.getSize(widthMeasureSpec);
_height = View.MeasureSpec.getSize(heightMeasureSpec);
Toast.makeText(getContext(), "Width = " + _width, Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), "Height = " + _height, Toast.LENGTH_SHORT).show();
setMeasuredDimension(_width, _height);
//_bitmap = Bitmap.createBitmap(_width, _height, Bitmap.Config.ARGB_8888);
//_canvas = new Canvas(_bitmap);
//calcLinePlacements();
//drawBoard();
}
I need to override onMeasure
method but when trying to override I get error:The method OnMeasure(int, int) of type DrawLnClass.DrawLn must override a superclass method
Here is my code:
public class DrawLnClass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new DrawLn(this));
}
public class DrawLn extends View {
Paint _paint;
int _height;
int _width;
Bitmap _bitmap;
Canvas _canvas;
Point[] xLine;
Point[] yLine;
public DrawLn(Context context) {
super(context);
_paint = new Paint();
_paint.setColor(Color.CYAN);
_paint.setStyle(Paint.Style.STROKE);
}
@Override
protected void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
//super.onMeasure(widthMeasureSpec, heightMeasureSpec);
_width = View.MeasureSpec.getSize(widthMeasureSpec);
_height = View.MeasureSpec.getSize(heightMeasureSpec);
Toast.makeText(getContext(), "Width = " + _width, Toast.LENGTH_SHORT).show();
Toast.makeText(getContext(), "Height = " + _height, Toast.LENGTH_SHORT).show();
setMeasuredDimension(_width, _height);
//_bitmap = Bitmap.createBitmap(_width, _height, Bitmap.Config.ARGB_8888);
//_canvas = new Canvas(_bitmap);
//calcLinePlacements();
//drawBoard();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将第一个 O 大写,它应该是 onMeasure 而不是 OnMeasure。
我打赌你很高兴你使用了@Override,否则你不会意识到该方法没有正确覆盖。
You capitalised the first O, it should be onMeasure not OnMeasure.
I bet you are glad you used @Override though, otherwise you wouldn't have realised the method wasn't correctly overriding.