android - Monospace Font: Increase textsize based on device size -
i have app must show printing-screen preview zebra printer. data printed pure-text , there maximum of 80 characters in 1 line.
the preview pure android: text views in vertical linear layout, 1 text view per line , monospace font. rendering works. phone have set font size 7dp, , 80 characters fit on screen in portrait mode.
now, there way calculate text size fit 80 characters on 1 line , being device size independant?
i tried following calculate text size , text scale:
private void calculatetextsizeandscale(int numberofchars, out float textsize, out float textscale) { var text = new string('m', numberofchars); var paint = new paint { textsize = 100f, textscalex = 1f }; paint.settypeface(typeface.monospace); var width = paint.measuretext(text); textsize = _screenwidth / width * 100f; paint.textsize = textsize; paint.textscalex = 1f; width = paint.measuretext(text); textscale = _screenwidth / width; } this seems correct screen resolution. works android phone in portrait mode, totally wrong landscape mode.
i use display.getmetrics retrieve screen width.
here screen shot on android phone
now, on tablet, looks different




Comments
Post a Comment