自定义SurfaceView:不显示绘制

时间:2013-04-16 04:10:52

标签: android surfaceview

我正在使用自定义surfaceview。但绘制不出现,视图是全黑的:

public class SV extends SurfaceView {

    Context context;

    public SV (Context a_context)
    {
        super(a_context);
        context = a_context;
    }

    @Override
    public void draw (Canvas c)
    {
        c.drawColor(0xFFFF0000);
        Paint p = new Paint();
        p.setColor(0xFFFFFFFF);
        c.drawCircle(c.getWidth()/2, c.getHeight()/2, 150, p);
    }

    @Override
    public void onDraw (Canvas c)
    {
        c.drawColor(0xFF0088FF);
    }

}

并在onCreate活动中:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    SV sv = new SV (this);
    setContentView(sv);
}

1 个答案:

答案 0 :(得分:0)

setWillNotDraw(false)语句添加到来自surfaceCreated()的{​​{1}}方法中。因此,您需要在SurfaceHolder.Callback

中添加以下代码
Activity