我正在使用自定义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);
}
答案 0 :(得分:0)
将setWillNotDraw(false)
语句添加到来自surfaceCreated()
的{{1}}方法中。因此,您需要在SurfaceHolder.Callback
。
Activity