简体   繁体   中英

Use setTextSize in proportion to screen

我需要一种方法让我的文本视图看起来与屏幕成比例地使用

settextsize()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM