自己定义的布局的OnDraw()方法没有得到所谓的布局、定义、方法、OnDraw

由网友(与爱意搭讪)分享简介:我定义的类这样的:public class TestMyFrameLayout extends FrameLayout{Paint mPaint;public TestMyFrameLayout(Context context, AttributeSet attrs) {super(context, attrs);}...

我定义的类这样的:

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(帆布油画)函数不获取调用,为什么呢?

But In fact TestMyFrameLayout.onDraw(Canvas canvas) function not getting called, why?

推荐答案

解决。加 this.setWillNotDraw(假); 在构造

阅读全文

相关推荐

最新文章