简体   繁体   中英

Canvas draw text vertically

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

    }}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM