【发布时间】:2011-12-08 13:47:37
【问题描述】:
我这样定义了一个类:
public class TestMyFrameLayout extends FrameLayout{
Paint mPaint;
public TestMyFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TestMyFrameLayout(Context context) {
super(context);
mPaint = new Paint();
mPaint.setColor(Color.GREEN);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(50f, 50f, 30, mPaint);
}
}
并称它为:
TestMyFrameLayout myFrameLayout = new TestMyFrameLayout(this);
LayoutParams myFrameLayoutParams = new LayoutParams(300,300);
myFrameLayout.setLayoutParams(myFrameLayoutParams);
setContentView(myFrameLayout);
但实际上 TestMyFrameLayout.onDraw(Canvas canvas) 函数没有被调用,为什么?
【问题讨论】:
-
你能在你使用它的地方显示代码吗?还要在 onDraw 之前添加
@Override:这将检查 Eclipse 中的拼写错误。 -
谢谢洛朗'。我的问题已经解决了。添加 this.setWillNotDraw(false);