为什么当我在画布对象上使用 drawRect() 时没有显示矩形,并且还在 onCreate 方法中声明了它。
代码
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymain);
Chronometer stopWatch = (Chronometer)findViewById(R.id.chrono);
mDrawingActivity = (DrawingActivity)findViewById(R.id.the_canvas);
Button b = (Button)findViewById(R.id.startButton);
b.setText("start");
b.setOnClickListener(this);
}
OnDraw() 方法
protected void onDraw(Canvas Square)
{
super.onDraw(Square);
Paint squareColor = new Paint();
squareColor.setColor(Color.CYAN); // change the box color to cyan
Square.drawRect(100,100,100,100, squareColor);
return;
}
澄清:即使按钮和计时器也没有显示,程序被强制关闭。