0

I am using the Android Monospace font for my game and have found that the font does not behave as expected. The game relies on the top characters and the underscores below being lined up with each other as clues to solve the cryptogram. However when the word is very close to the edge of the TextView as can be seen on the 5th line shown in the image the blue line of text goes onto the next line causing the clues and answers to be out of sync.

I'm using TextView.setTypeface(Typeface.MONOSPACE) for both lines (well... a font very closely based on it - the issue happens with MONOSPACE as well though).

Any ideas what could be causing this and how to fix it?

enter image description here

Uwais A
  • 737
  • 6
  • 23
  • They should be all be the same width but It looks like the underscore are treated specially, try a different font. Also see if the letter "W" has the same issue, the layout may be looking for white-space. – zaph Jun 22 '16 at 16:16
  • I checked for the whitespace issue - same problem as in the pic. Will try a different font... – Uwais A Jun 22 '16 at 16:17
  • Probably making the TextView one pixel (point) smaller or bigger should solve the problem in this case. – zaph Jun 22 '16 at 16:19
  • Yeah - I've got a pinch zooming on the text size implemented and that solves the problem. But I'd rather not have my users deal with that. – Uwais A Jun 22 '16 at 16:21

1 Answers1

0

So it turns out that the algorithm for TextView text wrapping is NOT as simple as - does the next word fit on this line --> if not put it on the next line.

Later in that screenshot the texts in black and blue differ (one shows the author of the quote the other does not). It seems the TextViewis trying to minimise lines and after this has been accomplished it minimises the width. Given the two texts in the screenshot are ~1 line of text different the small words at the end can be rearranged to make the TextView's width smaller. This is what causes the issues - the font is (as far as I can tell) in fact perfectly monospace.

This proper solution to this problem I suppose is to extend TextView and make a custom onDraw() to deal with the problem. For me, it was sufficient to make the two texts show exactly the same words (but with one being passed through a substitution cipher).

Uwais A
  • 737
  • 6
  • 23