我需要重写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();

        }

最佳答案

你把第一个o资本化了,应该是onmeasure而不是onmeasure。
不过,我敢打赌您很高兴使用了@override,否则您不会意识到该方法没有正确重写。

10-08 13:11