gpt4 book ai didi

android - 无法覆盖 onMeasure 方法

转载 作者:太空狗 更新时间:2023-10-29 15:37:26 24 4
gpt4 key购买 nike

我需要覆盖 onMeasure 方法,但在尝试覆盖时出现错误:DrawLnClass.DrawLn 类型的方法 OnMeasure(int, int) 必须覆盖父类(super class)方法

这是我的代码:

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,否则你不会意识到这个方法没有被正确覆盖。

关于android - 无法覆盖 onMeasure 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4865289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com