Which resource qualifier should I use to support 1080p, 720p android TV? - Android

前端 未结 2 1116
再見小時候
再見小時候 2020-12-10 06:13

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-sw1

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-10 07:15

    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).

提交回复
热议问题