如何在SurfaceView中旋转180度的文本

时间:2013-01-11 04:59:12

标签: android surfaceview

我想在SurfaceView中绘制一个文本,如下图所示

enter image description here

我该怎么办?请帮帮我。

1 个答案:

答案 0 :(得分:1)

使用以下代码替换onDraw(Canvas canvas)方法。

@Override
protected void onDraw(Canvas canvas) 
{
    canvas.drawColor( Color.WHITE );    

    int cx = 240;    // screenWidth/2
    int cy = 400;    // screenHeight/2

    Paint paint = new Paint();
    paint.setTextSize(30);
    paint.setColor( Color.BLACK );  
    paint.setAntiAlias(true);

    canvas.drawText("Name: A", 20, 40, paint);

    canvas.save();
    canvas.rotate(180, 240, 400);
    canvas.drawText("Name: B", 20, 40,paint);
    canvas.restore(); 
}