自己定义的布局的OnDraw()方法没有得到所谓的 [英] Own defined Layout , onDraw() method not getting called

查看:102
本文介绍了自己定义的布局的OnDraw()方法没有得到所谓的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义的类这样的:

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(假); 在构造

这篇关于自己定义的布局的OnDraw()方法没有得到所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆