다음과 같은 클래스를 정의했습니다.
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) 함수가 호출되지 않는 이유는 무엇입니까?
답변
해결되었습니다. this.setWillNotDraw(false);
생성자 추가