Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:33:17+00:00 2026-06-06T22:33:17+00:00

I have a SurfaceView where I’m drawing a matrix (game board) and each cell

  • 0

I have a SurfaceView where I’m drawing a matrix (game board) and each cell of the matrix is 40 pixels in height and width.

Within those cells, I have to store a Scrabble-like tile along the lines of:

+---------+
|    #    |
|   # #   |
|  #   #  |
|  #####  |
|  #   #  |
|       17|
+---------+

The letter is always a single letter and the number is always a number, at most two digits.

In order to do this I actually have calculated the position of the top-left pixel of the cell on my surface, and what I want to do is to draw the letter and the number to certain specifications.

I need to ensure that the number fits in a given region (say the bottom right 10×10 cells) and that the letter is centered in the tile without encroaching on the number region.

I currently plan on using the Paint.getTextBounds() to figure out the size of the largest letter and number and, if it turned out the size was too big, I’d simply do it in a smaller font.

I am, of course, open to suggestions for a better way. Even if there is no better way, I still have a problem.

The way I’m setting up the paint object is with:

numPaint = new Paint();
numPaint.setStrokeWidth(1);
numPaint.setColor(Color.BLACK);

and the actual drawing of the text is simply:

canvas.drawText(Integer.toString(num), pixcol + 30, pixrow + 30, numPaint);

That does place the number in the bottom right hand corner of the cell as expected but at no point have I specified a font size or anything else that’s likely to stop the text from going outside the cell if, for example, it ends up being 15×15 in size.

It appears to fit through sheer luck. In any case, I’ve set up the alphaPaint object exactly the same way but I want it to be a little bigger.

Sorry for meandering, I just wanted to ensure all the details were there. Bottom line question is: how do we set the font size of a paint object? The object has a getFontMetrics() but doesn’t appear to have the set... equivalent. The setTypeface() looked initially promising but that the font and bold/italic/etc, with no mention of forcing a specific size.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:33:18+00:00Added an answer on June 6, 2026 at 10:33 pm

    To set font size use numPaint.setTextSize(). Here is a link to the documentation public void setTextSize (float textSize)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my game, I have a surfaceView and I'm using a bitmap of resolution
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have a SurfaceView that is resposible for drawing a Bitmap as a background
I have a SurfaceView which is currently drawing a series of Bitmaps. These bitmaps
When you have a surfaceView class, used for animation/game/... you have the onTouchEvent() method
I have a game where I draw and move bitmaps over a SurfaceView. The
I am developing an Android game and I have my SurfaceView rendering the game
I have a game which has surfaceview and running on a thread. if I
I'm developing a 2d Game using Canvas/Surfaceview and have a problem with thread. So
I have an Activity with a SurfaceView that is managed by a game engine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.