Canvas draw text vertically

520 views Asked by At

I have put everything I need as I want it to be, my bitmaps, backgrounds and everything, what I need is to draw text that will be vertically shown. Here is my code for now:

 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);
        }

    }}
1

There are 1 answers

0
John On BEST ANSWER

First, you need Paint

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

Then, rotate your canvas

canvas.rotate(yourTextAngle, originX, originY);

Then, you draw your text

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

The text should be drawn vertically based on the angle you supplied.

Then if you want to restore the canvas after:

canvas.restore();

You should check out the information on Canvas. It is very thorough.