9

In order to define different dimension values for 1080p and 720p android TV, I need to decide which qualifier I should use. When I'm trying to use something like values-sw1080p,values-sw720p, it doesn't work. The values in dimes.xml doesn't affect anything. But it works if I'm using qualifier like -sw540dp,-sw360dp. I don't really understand why like that. Any idea? Thanks.

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
Bagusflyer
  • 12,675
  • 21
  • 96
  • 179
  • Display device that advertises 1080p typically refers to the ability to accept 1080p signals in native resolution format, which means there are a true 1920 pixels in width and 1080 pixels in height, – Murtaza Khursheed Hussain Jan 16 '15 at 07:01
  • where as sw-7080p in which "sw" stands for "Screen Width". – Murtaza Khursheed Hussain Jan 16 '15 at 07:02
  • Use neither, at least for things that are distinct for televisions. Bear in mind that layouts for phones and tablets are frequently unsuitable for televisions, due to dependence on the action bar, lacking support for overscan, and so on. Use `-television` as a resource set qualifier for television-centric resources. – CommonsWare Jan 17 '15 at 19:59

3 Answers3

13

There are three screen densities that can be considered for Android TV, and three corresponding qualifiers. These include:

  1. tvdpi - (213dpi) - intended for 720p televisions;
  2. xhdpi - (320dpi) - intended for 1080p (HD) televisions;
  3. xxxhdpi - (640dpi) - intended for 4k (Ultra HD) televisions.

But according to https://developer.android.com/training/tv/start/layouts.html#density-resources:

Your TV layout should target a screen size of 1920 x 1080 pixels [standard 1080p/HD], and then allow the Android system to downscale your layout elements to 720p if necessary.

This implies that, if you follow this advice and always design to a 1080p specs, you could use the -television UI Mode Qualifier and be done with it.

If you need to deliver different images and layouts for the different TV sizes, though, you can use the screen density qualifiers above.

The “standard” images and layouts for TV could be stored in a -xhdpi folder, as xhdpi is the qualifier used for 1080p TVs.

If (optional) high-resolution versions of images are desired for 4k TVs, they can be supplied as “2x” images, and stored in a drawable-xxxhdpi folder. Similarly, dimensions/layouts intended to only target 4k TVs could be placed in -xxxhdpi.

(Note in particular that the -tvdpi qualifier is specific to 720p, and is almost certainly not what you want to use to support modern TVs.)

The documentation is sparse and slightly contradictory, but I base this primarily on these sources:

https://developer.android.com/guide/practices/screens_support.html https://stackoverflow.com/a/11581786/925478

Community
  • 1
  • 1
Myk Willis
  • 12,306
  • 4
  • 45
  • 62
6

First of all, you are substantially correct. You can use

sw360dp/ : 720p screens
sw540dp/ : 1080p screens

The reason why sw720p/sw1080p don't work is because they don't exist as qualifiers.

This is the official documentation about working with different screen sizes. As you can read, there are two different units to take into account if you want to calculate your dp folder: the pixel count (e.g., 720) and the pixel density (that is, the dot-per-inch unit, or how many pixels fit into a single inch).

The formula is pretty simple:

px = dp * (dpi / 160)

while in this case we have:

dp = px * 160 / dpi

Of course, a TV can have different densities: this table tells you more about it (source: official documentation).

Densities table

Let's assume we have a 1080p display with an extra high density (@320 dpi). We do the math

dp = 1080 * 160 / 320 = 540

So we get the appropriate folder to put your resources in.


EDIT: on that same page, it is stated that there is a specific tvdpi qualifier that you can use for your TV-related resources (around 213 dpi).

Sebastiano
  • 12,289
  • 6
  • 47
  • 80
  • Thanks. Does that mean all 1080p and 720p TV are 320 DPI? (Because my customer don't know the DPI when I asked). – Bagusflyer Jan 16 '15 at 08:43
  • On that same page, it is stated that `tvdpi` is around 213 dpi. – Sebastiano Jan 18 '15 at 08:54
  • From my observation a 720p TV uses `tvdpi` whereas a 1080p TV uses `xhdpi`. This means **both** have density-independent dimensions of 960x540 dp (approximate for 720p) and both fit in the `sw540dp` bucket. Thus I believe using `sw360dp` to target 720p specifically is incorrect. – czak Jul 05 '16 at 20:31
  • @Sebastiano I have a image in 'drawable-television' qualifier, but Android pick another image (same name, of course) from 'drawable-sw600dp' . I want to pick it up from 'drawable-television' folder. What should I do? – Dr.jacky Jul 16 '16 at 07:04
  • `sw` -> smallest width, but 1080 and 720 refer to heights. `sw960` (half of 1920) would make sense for 1080p TV wouldn't it rather than `sw540`. – weston Jun 30 '17 at 19:10
  • @Sebastiano thx bro,your answer helped me understand all this stuff :) – Levon Petrosyan Oct 06 '17 at 06:08
1

try this

first you need to decide two things:
1. your screen density (dpi)
2. your screen dimension (px)

then apply this to get size in dp:
dp = px / dpi

example for 1080px/2.0dpi
dp = 540

then folder name would be: values-sw540dp

where
sw(smallest width) = Math.min(width, height);

//so orientation doesn't matter
  • This is as far I can see not a code snippet. It's a bit confusing. Read more about formatting [here](https://stackoverflow.com/editing-help). – Jolbas Jan 17 '21 at 07:46