Canvas 垂直绘制文本

Canvas draw text vertically

我已经按照我的意愿放置了我需要的所有东西,我的位图、背景和所有东西,我需要的是绘制将垂直显示的文本。这是我现在的代码:

 private void drawTables(Canvas canvas) {
    for (Table table : mTablesList) {
        float x = mWidht * table.getLeft() / 100;
        float y = mHeight * table.getTop() / 100;
        Rect rect = new Rect();
        rect.set(Math.round(x), Math.round(y), mWidht * table.getRight() / 100, mHeight * table.getBottom() / 100);
        if (table.isAvaliable()) {
            Drawable myDrawable = getResources().getDrawable(R.drawable.slobodan);
            Bitmap myBitmap = ((BitmapDrawable) myDrawable).getBitmap();
            table.setRect(rect);
            Bitmap nova = getResizedBitmap(myBitmap, 60, 60);
            Rect source = new Rect(0, 0, nova.getWidth(), nova.getHeight());
            table.setSlikaRezervacije(nova);
            canvas.drawBitmap(nova, source, table.getRect(), null);
        } else if (!table.isAvaliable()) {
            Drawable myDrawable = getResources().getDrawable(R.drawable.rezervisan);
            Bitmap myBitmap = ((BitmapDrawable) myDrawable).getBitmap();
            table.setRect(rect);
            Bitmap nova = getResizedBitmap(myBitmap, 60, 60);
            Rect source = new Rect(0, 0, nova.getWidth(), nova.getHeight());
            table.setSlikaRezervacije(nova);
            canvas.drawBitmap(nova, source, table.getRect(), null);
        }

    }}

首先,您需要Paint

Paint paint = new Paint();
// your paint settings such as stroke thickness and such

然后,旋转你的 canvas

canvas.rotate(yourTextAngle, originX, originY);

然后,你画你的文字

canvas.drawText("Your text", originX, originY, paint);

文本应根据您提供的角度垂直绘制。

那么如果你想恢复canvas之后:

canvas.restore();

您应该查看 Canvas 上的信息。讲的很透彻。