开发者

Can't override onMeasure method

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);
            _pai开发者_JAVA技巧nt = 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();

        }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜