mhplur
mhplur

Reputation: 218

Use setTextSize in proportion to screen

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

settextsize()

Upvotes: 0

Views: 176

Answers (1)

nKn
nKn

Reputation: 13761

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.

Upvotes: 1

Related Questions