반응형
자신이 정의한 레이아웃, 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 (Canvas canvas) 함수가 호출되지 않는 이유는 무엇입니까?
해결되었습니다. this.setWillNotDraw(false);
생성자 추가
참고 URL : https://stackoverflow.com/questions/7781892/own-defined-layout-ondraw-method-not-getting-called
반응형
'code' 카테고리의 다른 글
C ++에서 bool을 텍스트로 변환 (0) | 2020.09.18 |
---|---|
Java에서 문자열을 곱하여 시퀀스를 반복 할 수 있습니까? (0) | 2020.09.18 |
파이썬, 명령 줄 프로그램을 인터프리터가 아닌 임의의 것을 자동 완성하는 방법 (0) | 2020.09.18 |
C #의 문자열에서 마지막 문자를 제거합니다. (0) | 2020.09.18 |
node.js 자체 또는 정적 파일 제공을위한 nginx 프런트 엔드? (0) | 2020.09.18 |