Search code examples
androidandroid-layoutandroid-screen-supportandroid-screen

Configuration qualifers - Multiple screen size


I'm creating an application for smartphone tablet and televison. I'm creating my different displays, but I can not differentiate the tablet from the television. I read https://developer.android.com/guide/practices/screens_support.html

I have tried many things, large,xlarge sw720dp, W1024dp.. but nothings works. I work with the emulator.

AndroidTv 1080p API 25, Résolution 1920*1080:xhdpi

Nexus 5 API 24 Résolution 1080*1920:xxhdpi

Nexus 7 1200*1920 xhdpi

Thanks for your help !


Solution

  • The documentation you want is here: https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

    The important parts of this page are Table 2 (configuration qualifier names) and the section titled How Android Finds the Best-matching Resource.

    Reading these, it is clear that you will use the Smallest width qualifier to differentiate between phone and tablet devices, and the UI mode to differentiate between televisions and non-televisions. This directory structure should work:

    res/
        layout/
            layout.xml (default (i.e. phones))
        layout-sw600dp/
            layout.xml (non-televisions 600dp or wider (i.e. tablets))
        layout-sw600dp-television/
            layout.xml (televisions 600dp or wider)
    

    Because the Smallest width qualifier has a higher precedence than the UI mode qualifier, if you tried to just use layout-television you would find that your TV still used the -sw600dp layout.