0

所以我有这个 onDraw 功能

protected void onDraw(Canvas canvas) {
                    Paint paint = mPaint;

                    canvas.drawColor(Color.WHITE);

                    paint.setAntiAlias(true);
                    paint.setColor(Color.BLACK);
                    paint.setStyle(Paint.Style.FILL);

                    int w = canvas.getWidth();
                    int h = canvas.getHeight();
                    int cx = w / 2;
                    int cy = h / 2;

                    canvas.translate(cx, cy);
                    if (mValues != null) {            
                        canvas.rotate(-mValues[0]);
                    }
                    canvas.drawPath(mPath, mPaint);

                    Paint paint1 = new Paint(); 


                    paint1.setColor(Color.BLACK); 
                    paint1.setTextSize(25); 
                    canvas.drawText("Some Text", 10, 25, paint1); 

                }

它的作用是绘制一个正在旋转的箭头,并且文本也在箭头附近旋转我想要的是箭头下方某处的静态文本......或类似的东西。

4

1 回答 1

1

使用canvas.save();canvas.restore();类似的东西:

protected void onDraw(Canvas canvas) {
    Paint paint = mPaint;

    canvas.drawColor(Color.WHITE);

    paint.setAntiAlias(true);
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.FILL);

    int w = canvas.getWidth();
    int h = canvas.getHeight();
    int cx = w / 2;
    int cy = h / 2;

    canvas.save();
    canvas.translate(cx, cy);
    if (mValues != null) {            
           canvas.rotate(-mValues[0]);
    }
    canvas.drawPath(mPath, mPaint);
    canvans.restore();

    Paint paint1 = new Paint(); 


    paint1.setColor(Color.BLACK); 
    paint1.setTextSize(25); 
    canvas.drawText("Some Text", 10, 25, paint1); 

}

希望有帮助。

于 2012-08-08T00:04:30.573 回答