1

I want to have a textview which only allows 16 characters per line, but uses the whole width of the textview. By trying out different values, I found out that fontSize = 23sp worked on a 480x800 screen but not on other screen resolutions.

How can I scale the fontsize so there will be maximum 16 characters per line on any screen?

Greetings

  • 1
    Eventually you could try using "dp" (or "dip", is the same), not "sp". DIP -> Density-independent pixels. SP -> scale-independent pixels – Hitman Apr 17 '14 at 09:43
  • Here is link http://stackoverflow.com/questions/5033012/auto-scale-textview-text-to-fit-within-bounds – Vijay Vala Apr 17 '14 at 09:49
  • Sry, I actually used dp not sp. The AutoResizer is not the thing I am looking for because it should not resize the size with the text, it should always be the same size but only allow 16 characters on every screen. – user3544662 Apr 17 '14 at 09:51

1 Answers1

0

Try this may be it helps you and check the size of text view for screen.

 DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
        int Displaywidth = metrics.widthPixels;
        int Displayheight = metrics.heightPixels;


        if (Displaywidth <= 480 && Displayheight <= 800) {

                    text.setTextSize(TypedValue.COMPLEX_UNIT_SP,23);
        }

        else if (Displaywidth <= 720 && Displayheight <= 1280) {


              text.setTextSize(TypedValue.COMPLEX_UNIT_SP,30);

        }

        else {
             text.setTextSize(TypedValue.COMPLEX_UNIT_SP,30);


        }
  • Thank you, this works pretty well. But is there a formula to adjust the font size or do I have to go through all the resolutions? – user3544662 Apr 17 '14 at 13:10
  • there is not any specific formula for size of text only for 16char. –  Apr 17 '14 at 13:26