我需要覆盖onMeasure
方法,但在尝试覆盖时我得到错误:
The method OnMeasure(int, int) of type DrawLnClass.DrawLn must override a superclass method
这是我的代码:
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();
}
答案 0 :(得分:12)
你把第一个O大写,它应该是onMeasure而不是OnMeasure。
我敢打赌你很高兴你使用了@Override,否则你就不会意识到这个方法没有正确覆盖。