1

I was wondering is it possible to use drawText with an array so that it doesn't place each word onto of the other?

 for(int count =0; count<2; count++)
    {
        canvas.drawText(words[count], x, y, paint);

    }//for

1 Answer 1

3

You need to change x or y, so:

for (int count = 0; count < words.length; count++) {
  canvas.drawText(words[count], x + 10 * count, y, paint);
}

Here, word[0] would be drawn at (x, y) and word[1] would be drawn at (x + 10, y). This isn't very robust, however; it assumes that all words are 10 px wide.

Sign up to request clarification or add additional context in comments.

2 Comments

Great for basic concept and explanation. Depending on the length of each word in the array x or y values can be incremented.
There's also a measureText(String) method on Paint that should help, e.g. x += paint.measureText(words[count]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.