我需要重写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();
}发布于 2011-02-02 00:43:55
你大写了第一个O,它应该是OnMeasure而不是onMeasure。
我打赌你很高兴你使用了@Override,否则你不会意识到这个方法没有正确地覆盖。
https://stackoverflow.com/questions/4865289
复制相似问题