0

I need a way for my textview look the same size in proportion to the screen using

settextsize()
mhplur
  • 218
  • 1
  • 3
  • 16

1 Answers1

1

The best way you can achieve that is using sp as the unit of measure for your text. sp is a scale independent measurement unit which will make easier to integrate your text within different devices with different sizes and resolutions. As of the reference:

sp

Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

You'll see more info on this SO question and this reference link will help you too.

---- EDIT ----

To set your size programmatically, you can use something like this:

tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);

That would set the equivalent to 12sp to your text size.

Community
  • 1
  • 1
nKn
  • 13,691
  • 9
  • 45
  • 62
  • Thanks my friend, but does not work, the textview not resized when screen change – mhplur Feb 11 '14 at 16:59
  • The solution I've provided doesn't make your text resize if the screen changes, it's just a way of defining the text size independently to the size physical size and resolution. If you meant **orientation**, you can use the `getResources().getConfiguration().orientation` property. – nKn Feb 11 '14 at 17:04
  • Thanks, but i used in my code this: `metrics = getApplicationContext(). getResources().getDisplayMetrics(); float Textsize =txt_pri.getTextSize()/metrics.density`; but doesn't work,I am not referring to the orientation of the screen. – mhplur Feb 11 '14 at 17:12