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

portrait phone portrait phone

landscape phone landscape phone

now, on tablet, looks different

portrait tablet portrait tablet

landscape tablet landscape tablet


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -