TimmyMa
TimmyMa

Reputation: 175

Convert px to dp and sp in /values/dimen.xml in Android

I know we should use dp/sp instead of px in UI design, but the UI designer I work with just gives me his design in pixels in 1280x720. How should I convert the pixels in 1280x720 to dp/sp, and support multiple screens?

I checked the doc, 30px in 1280x720 = 15dp in xhdpi. Should I make a /values-xhdpi/dimen.xml file in my project? And what about other resolutions? How should I deal with ldpi, mdpi, hdpi, xxhdpi, xxxhdpi?

Also, I got the text sizes in pixels too. Do I need to do the same thing as I did with dp?

Upvotes: 2

Views: 1420

Answers (1)

Related Questions