0

In my android app, there is a certain layout with a fixed height. In this layout, there are some TextView s arranged vertically. I have set the font size of text fields to be somewhat larger (18sp).

In almost all the devices I checked, The text fits inside the fixed sized layout. But in few devices, The bottom TextView gets cropped out of the layout.

If the proportion between text unit size (sp) and the layout unit height (dp) is the same in all devices, I wouldn't expect this to happen.

So, is this due to something wrong with the devices? Is there any way I can fix this?

Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179
  • You asking about how pixel density works on different devices? – OneCricketeer Mar 03 '16 at 01:50
  • @cricket_007 What I am asking is whether I can expect the proportion between x dp wide layout and a y sp sized TextView to be the same across all the devices. – Lahiru Chandima Mar 03 '16 at 01:58
  • 1
    Seeing as `sp` is a scaled version of `dp`, then maybe. It may be worth reading this, though. http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-on-android – OneCricketeer Mar 03 '16 at 02:19
  • You're not saying how you're computing the fixed height of the layout. Are you sure you're doing that properly? Wouldn't you like to share the code and some screenshots so everyone can see what's going on? – Doug Stevenson Mar 03 '16 at 04:49

2 Answers2

1

Screen density is different than screen dimensions. dp normalizes densities across devices, but they can still have varying screen heights and widths. The obvious example is tablet vs phones, tablets have the same screen densities as phones but much larger screen dimensions. Just like that, some phones have smaller screens than others, so you need to take that into account when using fixed height layouts.

To get around this problem, you can take advantage of the width and smallest-width resource buckets and provide different layouts for smaller devices.

telkins
  • 10,440
  • 8
  • 52
  • 79
0

As it seems, the proportion between a unit sp and a unit dp depends on the font size setting (Settings->Display->Font size).

I could recreate the issue on other devices when I set the font size to be Huge.

So, it is not a good idea to set fixed sizes to layouts containing text.

Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179