Santiago Serrano2,754 Points
When I set the size of a view in dp, does its physical size remain the same?
Ok, according to the Google Developers' guide "Support different pixel densities", one dp is a virtual pixel unit that's roughly equal to one pixel on a medium-density screen.
Correct me if I'm wrong, but if we do the math, since a medium-density screen is 160dpi, a dp should be equal to 1inch/160. Since this result would be in inches, a view whose size is set in dp (or in sp) should have the same physical size, no matter in which screen size and in which pixel density it is displayed.
But there is a thing that doesn't make sense to me (if what I stated before is correct). Let's say I have a button which will be 10 x 10cm in a TV. In a phone, that button would be ridiculously huge. This would mean that dp wouldn't be that good to use when using different screen sizes.
The problem here is screen density vs screen size. Phones come in different densities and, you are correct, to make sure that a view will have the same size on different phone screens, no matter the screen density, we use the dp unit (instead of pixels).
However, screen size is a different matter. If you want your Android phone app to look OK on a TV screen (or vice versa), you will have to rethink the UI for each of these screens. I am not familiar with developing for TVs or Wear OS, but when you build an Android app for phones, it is common to create a separate layout for tablets, and also sometimes a separate layout for phones in landscape mode. I'm afraid there is no one-size-fits-all layout for phones, tablets, TVs, Wear OS and Android Auto.