当我使用drawRect()时,为什么矩形没有显示?

sha*_*non 0 eclipse android android-canvas

当我在canvas对象上使用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);
}
Run Code Online (Sandbox Code Playgroud)

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;
    }
Run Code Online (Sandbox Code Playgroud)

澄清:即使按钮和计时器也没有显示,程序被强制关闭.

Sha*_*lik 7

您正在绘制一个点矩形.改变线

Square.drawRect(100,100,100,100, squareColor);
Run Code Online (Sandbox Code Playgroud)

Square.drawRect(100, 100, 200, 200, squareColor)
Run Code Online (Sandbox Code Playgroud)

这是doc的定义.

drawRect(float left, float top, float right, float bottom, Paint paint)
Run Code Online (Sandbox Code Playgroud)

使用指定的绘制绘制指定的Rect.矩形将根据绘画中的样式填充或加框.

参数left要绘制的矩形的左侧顶部要绘制的矩形的顶部右侧要绘制的矩形的右侧底部要绘制的矩形的底部绘制用于绘制矩形的绘制