Resource qualifiers on Surface Duo
When your app is spanned across a dual-screen device, you may see that the layout that you are currently using is not perfectly adapted for this configuration. As an example, you might observe that there is content that is hidden by the hinge, and might consider some layout adjustments so that your app looks and behaves better when used on a dual-screen device. To manage these adjustments, Android provides qualifiers to handle multiple configurations, so whether your app is running on a device with a small screen, a tablet with 10” screen in landscape mode, or on Surface Duo, you can use different qualifier values to help you optimize your app for specific device configurations.
Detecting the Surface Duo
For Surface Duo, you can use the qualifier sw720dp-2784×1800, for example:
- values-sw720dp-2784×1800 - for resource values, like strings.xml files
- layout-sw720dp-2784×1800 - for layout XML files
Surface Duo will take the resources located there and will use them. If no specific resources are available, Surface Duo will apply the existing qualifiers in order of precedence.
How the qualifier is constructed
The Surface Duo dimensions indicates the device in dual-landscape mode has a width of 720dp. This is the value we will use as the devices smallest width and this value doesn’t change when the screen orientation changes, so this value remains constant whether we are in dual-portrait or dual-landscape mode. This is represented as sw720dp in the qualifier.
The 2784×1800 value provides a more specific configuration. Since sw720dp can be shared with many available tablets on the market, the 2784×1800 value is the specific width and height of the Surface Duo device in pixels. Surface Duo has a 1350px width per screen, so 1350 x 2 = 2700px; if we also add the width of the mask/hinge (84px) the total width is 2784px (2700 + 84 = 2784px). The screen height is 1800px, making the screen dimensions 2784x1800px.
Hardcoding resources to specific values can have unintended consequences, if a new device appears with the same screen size then it would also match the qualifier. Plan your resources accordingly.