{"id":241,"date":"2020-04-09T12:00:13","date_gmt":"2020-04-09T19:00:13","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/surface-duo\/?p=241"},"modified":"2020-08-18T10:57:14","modified_gmt":"2020-08-18T17:57:14","slug":"introducing-surfaceduolayout-designer-preview-for-android-studio-developers","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/surface-duo\/introducing-surfaceduolayout-designer-preview-for-android-studio-developers\/","title":{"rendered":"Introducing SurfaceDuoLayout Designer Preview for Android Studio Developers"},"content":{"rendered":"<p>Hello Android dual-screen developers!<\/p>\n<p>In the March 26th blog post, we introduced the <a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/introducing-dual-screen-layouts-android\/\">Dual Screen Layout<\/a>.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-253\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/03\/emulator-2x2-800.png\" alt=\"Wide and tall device screenshots\" width=\"800\" height=\"452\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/03\/emulator-2x2-800.png 800w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/03\/emulator-2x2-800-300x170.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/03\/emulator-2x2-800-768x434.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>Figure 1: Single-screen and dual-screen layouts using SurfaceDuoLayout<\/p>\n<p>When using the SurfaceDuoLayout, you can implement dual-screen behavior by either using layouts or by listening for screen change events and manipulating fragments, or with a combination of the two approaches.<\/p>\n<p>Our CompanionPaneLevel2 sample helps create a sophisticated, responsive UI declaratively. You can view this behavior in these samples (<a href=\"https:\/\/github.com\/microsoft\/surface-duo-sdk-samples\/tree\/master\/CompanionPaneLevel2\">Java<\/a>,\u00a0<a href=\"https:\/\/github.com\/microsoft\/surface-duo-sdk-samples-kotlin\/tree\/master\/CompanionPaneLevel2\">Kotlin<\/a>).<\/p>\n<p><span style=\"font-size: 14pt;\"><strong>Today we are releasing an update to this layout control and adding Designer Layout Preview support for developers using Android Studio.<\/strong><\/span><\/p>\n<h2>Designer Preview<\/h2>\n<p>As part of the Android Studio Design editor, you can now preview your layout in different modes and postures. For DuoKLayout, it enables both a single screen layout preview and a dual screen layout preview.<\/p>\n<p>You can also modify the layout and add buttons or other common controls.<\/p>\n<p>To start utilizing the Designer Preview, you will need to add these two new attributes to the layout XML:<\/p>\n<ol>\n<li>tools_screen_mode \u2013 Defines the designer preview for single screen layout or dual screen layouts<\/li>\n<li>tools_hinge_color \u2013 Defines the color of the hinge<\/li>\n<\/ol>\n<p>These attributes are in addition to existing ones below which define the single and dual-screen behaviors:<\/p>\n<ul>\n<li>single_screen_layout_id \u2013 Layout to load in single screen mode, or on other devices<\/li>\n<li>dual_screen_start_layout_id \u2013 Layout for the left-side screen<\/li>\n<li>dual_screen_end_layout_id \u2013 Layout for the right-side screen<\/li>\n<\/ul>\n<p>By default, the designer layout preview will show the single-screen mode as a preview, but you can change the designer preview mode to support a dual-screen designer preview.<\/p>\n<p>To enable the designer preview mode for a specific screen mode, you will need to set the attribute \u201capp:tools_screen_mode\u201d to either \u201cdual_screen\u201d or \u201csingle_screen\u201d.<\/p>\n<p>Both options are shown below:<\/p>\n<p><img decoding=\"async\" width=\"1102\" height=\"703\" class=\"wp-image-243\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-1.png\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-1.png 1102w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-1-300x191.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-1-1024x653.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-1-768x490.png 768w\" sizes=\"(max-width: 1102px) 100vw, 1102px\" \/><\/p>\n<p>Figure 2: Designer Preview for a <strong>single-screen<\/strong> layout using SurfaceDuoLayout<\/p>\n<p><img decoding=\"async\" width=\"1091\" height=\"696\" class=\"wp-image-244\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-2.png\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-2.png 1091w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-2-300x191.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-2-1024x653.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-2-768x490.png 768w\" sizes=\"(max-width: 1091px) 100vw, 1091px\" \/><\/p>\n<p>Figure 3: Designer Preview for a <strong>dual-screen<\/strong> layout using SurfaceDuoLayout<\/p>\n<p>Notice that when dual-screen is selected, we reduce the gap between the two screens to simulate how this will look on the real devices, or on the emulator. The size of the gap emulates the real ratio of 84 pixels that would be seen on a real device.<\/p>\n<p>Another design element we thought through was the Dark Theme mode for the layout. We decided to add an option to change the color of the hinge from black to white so it would be in contrast to the left and right screen themes.<\/p>\n<p>To make this design change, use the attribute \u201ctools_hinge_color\u201d and set it to \u201cwhite\u201d or \u201cblack\u201d.<\/p>\n<p><img decoding=\"async\" width=\"1802\" height=\"1148\" class=\"wp-image-245\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-3.png\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-3.png 1802w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-3-300x191.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-3-1024x652.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-3-768x489.png 768w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-3-1536x979.png 1536w\" sizes=\"(max-width: 1802px) 100vw, 1802px\" \/><\/p>\n<p>Figure 4: Changing the hinge color to white to support a Dark Theme<\/p>\n<p><img decoding=\"async\" width=\"1802\" height=\"1148\" class=\"wp-image-246\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-4.png\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-4.png 1802w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-4-300x191.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-4-1024x652.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-4-768x489.png 768w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-4-1536x979.png 1536w\" sizes=\"(max-width: 1802px) 100vw, 1802px\" \/><\/p>\n<p>Figure 5: Dual-screen Designer Preview in double landscape mode<\/p>\n<p>Stitching it all together, your layout XML should look similar to this:<\/p>\n<p><img decoding=\"async\" width=\"465\" height=\"218\" class=\"wp-image-247\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-5.png\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-5.png 465w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-5-300x141.png 300w\" sizes=\"(max-width: 465px) 100vw, 465px\" \/><\/p>\n<p>Our samples have been updated, and can be viewed in GitHub for <a href=\"https:\/\/github.com\/microsoft\/surface-duo-sdk-samples\/tree\/master\/CompanionPaneLevel2\">Java<\/a> and \u00a0<a href=\"https:\/\/github.com\/microsoft\/surface-duo-sdk-samples-kotlin\/tree\/master\/CompanionPaneLevel2\">Kotlin<\/a><\/p>\n<h2>Using Fragments<\/h2>\n<p>Next, we will talk about how to preview the SurfaceDuoLayout when we add fragments that are declared in layout files.<\/p>\n<p>To add fragments to the layout file, you can use these attributes:<\/p>\n<ul>\n<li>app:show_in_single_screen &#8211; Adds a layout file that will override the preview for Single-screen<\/li>\n<li>app:show_in_dual_screen_start &#8211; Adds a layout file that will override the preview for dual-screen-start<\/li>\n<li>app:show_in_dual_screen_end &#8211; Adds a layout file that will override the preview for dual-screen-start<\/li>\n<\/ul>\n<p>These attributes work as tools:layout <a href=\"https:\/\/developer.android.com\/studio\/write\/tool-attributes#toolslayout\">attribute<\/a>s for fragments.<\/p>\n<p>These attributes will help you transition from this preview:<\/p>\n<p><img decoding=\"async\" class=\"wp-image-248\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-6.png\" width=\"503\" height=\"378\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-6.png 689w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-6-300x226.png 300w\" sizes=\"(max-width: 503px) 100vw, 503px\" \/> <img decoding=\"async\" class=\"wp-image-249\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-7.png\" width=\"234\" height=\"375\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-7.png 330w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-7-187x300.png 187w\" sizes=\"(max-width: 234px) 100vw, 234px\" \/><\/p>\n<p>To this preview:<\/p>\n<h2><img decoding=\"async\" class=\"wp-image-250\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-8.png\" width=\"502\" height=\"380\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-8.png 701w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-8-300x228.png 300w\" sizes=\"(max-width: 502px) 100vw, 502px\" \/><img decoding=\"async\" class=\"wp-image-251\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-9.png\" width=\"234\" height=\"377\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-9.png 330w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-9-186x300.png 186w\" sizes=\"(max-width: 234px) 100vw, 234px\" \/><\/h2>\n<h2><\/h2>\n<h2>How to get this update<\/h2>\n<p>To get this feature update, follow our public Maven repo steps below and update the dualscreen-layout lib to version 0.9.2.<\/p>\n<p>Follow these steps in your Android Studio project:<\/p>\n<ol>\n<li>In the top-level\u00a0<strong>build.gradle<\/strong>\u00a0file, add these lines inside the\u00a0allprojects { repositories {\u00a0section:<\/li>\n<\/ol>\n<pre class=\"prettyprint\"><code>maven {\r\n\u00a0\u00a0\u00a0\u00a0url 'https:\/\/pkgs.dev.azure.com\/MicrosoftDeviceSDK\/DuoSDK-Public\/_packaging\/Duo-SDK-Feed\/maven\/v1'\r\n}<\/code><\/pre>\n<ol>\n<li>In your module-level\u00a0<strong>build.gradle<\/strong>\u00a0file, add this line in the\u00a0dependencies {\u00a0section:<\/li>\n<\/ol>\n<p><code>implementation 'com.microsoft.device:dualscreen-layout:0.9.2'<\/code><\/p>\n<ol>\n<li>Java projects should also add this line to their\u00a0<strong>build.gradle<\/strong>\u00a0dependencies, because the library is built with Kotlin:<\/li>\n<\/ol>\n<p><code>implementation \"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version\"<\/code><\/p>\n<h2>FAQ:<\/h2>\n<p><strong>I updated the library, but I get this error in layout preview<\/strong>:<\/p>\n<p><img decoding=\"async\" width=\"596\" height=\"126\" class=\"wp-image-252\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-10.png\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-10.png 596w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/04\/word-image-10-300x63.png 300w\" sizes=\"(max-width: 596px) 100vw, 596px\" \/><\/p>\n<p><strong>Solution: <\/strong>Try to clean and rebuild your project.<\/p>\n<p><strong>I made some layout modification, but they don\u2019t show up in the layout preview<\/strong>.<\/p>\n<p><strong>Solution:<\/strong> Rebuild your project so that the layout preview is aware of your modifications.<\/p>\n<h2>Resources and feedback<\/h2>\n<p>Refer to the <a href=\"https:\/\/docs.microsoft.com\/dual-screen\/android\/api-reference\/dualscreen-library\/\">SurfaceDuoLayout documentation<\/a> for more detailed explanations of the alternative approaches for using the SurfaceDuoLayout control.<\/p>\n<p>We are building our roadmap for additional controls and would love to get your feedback on what else we can provide as well as hear about your experiences using the SDK, the Emulator, or any other thoughts you may have.<\/p>\n<p>Please reach out using our <a href=\"http:\/\/aka.ms\/SurfaceDuoSDK-Feedback\">feedback forum<\/a> or message me on <a href=\"https:\/\/twitter.com\/gmerin\">Twitter<\/a> or <a href=\"https:\/\/github.com\/guymerin\">GitHub<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Android dual-screen developers! In the March 26th blog post, we introduced the Dual Screen Layout. Figure 1: Single-screen and dual-screen layouts using SurfaceDuoLayout When using the SurfaceDuoLayout, you can implement dual-screen behavior by either using layouts or by listening for screen change events and manipulating fragments, or with a combination of the two approaches. [&hellip;]<\/p>\n","protected":false},"author":17398,"featured_media":245,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31,46,45,29,30],"class_list":["post-241","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-surface-duo-sdk","tag-dual-screen-development","tag-surface-duo","tag-surface-duo-sdk","tag-surfaceduo","tag-surfaceduo-sdk"],"acf":[],"blog_post_summary":"<p>Hello Android dual-screen developers! In the March 26th blog post, we introduced the Dual Screen Layout. Figure 1: Single-screen and dual-screen layouts using SurfaceDuoLayout When using the SurfaceDuoLayout, you can implement dual-screen behavior by either using layouts or by listening for screen change events and manipulating fragments, or with a combination of the two approaches. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/241","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/users\/17398"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/comments?post=241"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/241\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media\/245"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media?parent=241"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/categories?post=241"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/tags?post=241"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}