Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Incorrect TextSize unit

In the Build a Weather App course, Building the Weather UI/The Foggy Bottom lesson, @7:36, the instructor says "TextSize, we'll do 18 dp" when it should be "TextSize, we'll do 18 sp "

1 Answer

Binyamin Friedman
Binyamin Friedman
14,615 Points

As stated at "https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dip-dp-and-sp", sp is the same as dp, but takes user preferences into account.

You're right, usually sp is preferable to use. I think in this scenario, with lots of text boxes in precise locations, using sp could mess with the layout. A user that sets his font size to large could get a funky looking ui. There might be a better explanation though...

Thanks for your answer. To be honest, I do not believe there's a reason behind that use of dp here. While I agree that if the TextView size was fixed (in dp), setting the textSize to sp might then make the text overflow the view when the user sets their font size to large, that's not the case here. All the TextViews in that UI are wrap_content and all the other textSizes are in sp. We're also using a ConstraintLayout, all in all making the UI very flexible and responsive. I truly believe it is a genuine mistake here and that sp should have been used. It might confuse other students too, especially since a question in the following quiz asks what unit should be used for textSize (sp being the answer).