1

In one of my Activities I'd like to adjust an amount of textual content according to current screen size. What metric should I rely on?

Just width in pixels seems not too reliable since font scaling can be very different. On the other hand DisplayMetrics's DENSITY_280, DENSITY_400 ... seem too broad. Is there any normalized metric available like width_in_pixels * font_scaling?

Just in case: My min SDK verion is 15 (4.0.3)

src091
  • 2,807
  • 7
  • 44
  • 74

2 Answers2

2

When specifying text size, always use sp:

<TextView android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="20sp" />

more details here and here

Community
  • 1
  • 1
hornet2319
  • 379
  • 3
  • 15
1

you can get values like dpi from DisblayMetrics , look here docs

also, there is a built-in converter for different size metrics in api, TypedValue.applyDimension() , which can be used to get pixels from sp or dp

Raiv
  • 5,731
  • 1
  • 33
  • 51