old*_*hou 84 android android-layout
我定义了一个类:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
并称之为:
TestMyFrameLayout myFrameLayout = new TestMyFrameLayout(this);
LayoutParams myFrameLayoutParams = new LayoutParams(300,300);
myFrameLayout.setLayoutParams(myFrameLayoutParams);
setContentView(myFrameLayout);
Run Code Online (Sandbox Code Playgroud)
但实际上TestMyFrameLayout.onDraw(Canvas canvas)函数没有被调用,为什么呢?
old*_*hou 196
解决了.添加
this.setWillNotDraw(false);
构造函数
| 归档时间: |
|
| 查看次数: |
20368 次 |
| 最近记录: |