了解更多请访问:鸿蒙科技社区https://harmonyos.51cto.comfile:[Kapok]易玩平行视界(上){"easyGoVersion":必填,固定值为"1.0","client":必填,程序的应用包名"logicEntities":[{"head":{"function":必填,调用组件名,固定值为"magicwindow","required":必填,保留字段,固定值为"true"},"body":{"mode":必填,basic分屏模式。"0":购物模式,abilityPairs节点不生效;"1":自定义模式(包括导航模式),"abilityPairs":[自定义模式下必选,配置from页面到to页面的分屏显示{"from":自定义模式下必选,AbilityA的包名,"to":自定义模式必填,AbilityB的包名,}表示AStartBontop,触发分屏(A左B右)],"Abilities":[optional,applyPageAbilityattributelist,{"name":optional,PageAbility包名,"defaultFullScreen":可选,PageAbility是否支持默认全屏启动。"true":支持;,"false":不支持},{"name":可选,PageAbility包名,"defaultFullScreen":可选,PageAbility默认是否支持全屏."true":支持;,"false":notsupported}],"UX":{可选,页面UX控制配置设置“isDraggable”:可选,是否支持分屏窗口拖动(只对平板产品有效)。"true":支持;"false":不支持(默认值为false)}}}]}导航模式代码文件代码文件结构如下:下面只给出部分关键代码FirstAbilitySlice.java:publicclassFirstAbilitySliceextendsAbilitySlice{@OverridepublicvoidonStart(Intentintent){super.onStart(intent);super.setUIContent(ResourceTable.Layout_ability_first);findComponentById(ResourceTable.Listener.bsetn_yes)(newComponent.ClickedListener(){@OverridepublicvoidonClick(Componentcomponent){getContext().setDisplayOrientation(AbilityInfo.DisplayOrientation.LANDSCAPE);//申请横向进入全屏显示状态}});findComponentById(ResourceTable.Id_btn_no).setClickedListener(newComponent.ClickedListener(){@OverridepublicvoidonClick(Componentcomponent){getContext().setDisplayOrientation(AbilityInfo.DisplayOrientation.PORTRAIT);//调用申请纵向退出全屏状态}});findComponentById(ResourceTable.Id_btn2).setClickedListener(newComponent.ClickedListener(){@OverridepublicvoidonClick(Componentcomponent){Operationoperation=newIntent.OperationBuilder().withDeviceId("").withBundleName(getBundleName()).withAbilityName(SecondAbility.class.getName()).build();intent.setOperation(operation);startAbility(intent);}});findComponentById(ResourceTable.Id_btn3).setClickedListener(newComponent.ClickedListener(){@OverridepublicvoidonClick(Componentcomponent){Operationoperation=newIntent.OperationBuilder().withDeviceId("").withBundleName(getBundleName()).withAbilityName(ThridAbility.class.getName()).build();intent.setOperation(operation);startAbility(intent);}});findComponentById(ResourceTable.Id_btn_back).setClickedListener(newComponent.ClickedListener(){@OverridepublicvoidonClick(Componentcomponent){terminateAbility();}});}@OverridepublicvoidonActive(){super.onActive();}@OverridepublicvoidonForeground(Intentintent){super.onForeground(intent);}}config.json配置文件的模块对象中新增metaData:"metaData":{"customizeData":[{"名称":"EasyGoClient","value":"true"}]}在src->main->resources->rawfile目录下添加easygo.json配置文件:{"easyGoVersion":"1.0","client":"com.test.mydemo2","logicEntities":[{"head":{"function":"magicwindow","re??quired":"true"},"body":{"mode":"1","abilityPairs":[{"from":"com.test.mydemo2.NavigationAbility","to":"*"}],"能力":[{"name":"com.test.mydemo2.MainAbility","defaultFullScreen":"false"},{"name":"com.test.mydemo2.NavigationAbility","defaultFullScreen":"false"},{"name":"com.test.mydemo2.FirstAbility","defaultFullScreen":"false"},{"name":"com.test.mydemo2.SecondAbility","defaultFullScreen":"false"},{"name":"com.test.mydemo2.ThridAbility","defaultFullScreen":"false"}],"UX":{"isDraggable":"true"}}}]}以上代码为easygo.json配置文件相关元素说明如下:{"easyGoVersion":"client":"logicEntities":[{"head":{"function":"required":},"body":{"mode":"abilityPairs":[{"from":自定义模式必填,AbilityA的包名,"to":"*"表示任意PageAbility,}表示在A上启动任意PageAbility,触发分屏(A左orright)],"Abilities":[{"name":"defaultFullScreen":}],"UX":{"isDraggable":}}}]}运行效果平板横屏运行效果如下:总结导航模式是系统提供的一个“分栏”,可以帮助用户在应用中高效的来回切换,从上面的操作结果我们可以发现,导航模式具有三个特点:1.屏幕右半边始终显示最后一个窗口。2.导航主页固定在左边,左键点击是ri正确的,点击右侧退出右侧。3、如果返回左触发器,则退出左右分屏的所有界面;如果右触发器返回,则右返回上一级,左保持不变。全屏显示PageAbility另外,在平行水平状态下,有些PageAbilities要全屏显示,分别有动态方法和静态方法:动态方法:全屏显示:调用如下接口申请横屏方向进入全屏显示状态:getContext().setDisplayOrientation(AbilityInfo.DisplayOrientation.LANDSCAPE);退出全屏:调用申请竖屏方向退出全屏状态:getContext().setDisplayOrientation(AbilityInfo.DisplayOrientation.PORTRAIT);静态方法:在easygo.json文件的Abilities属性中,配置PageAbility的defaultFullScreen为true,实现PageAbility默认全屏显示:{"name":"com.test.mydemo2.MainAbility","defaultFullScreen":"true"}在config.json文件的Abilities属性中,配置PageAbility的orientation为landscape(横屏),PageAbility会一直全屏显示:{"orientation":"landscape","visible":true,"name":"com.test.mydemo2.MainAbility","icon":"$media:icon","description":"$string:mainability_description","label":"$string:entry_MainAbility","type":"page","launchType":"standard"}购物模式代码文件代码文件结构如下:config.json配置文件的module对象中只给出了部分关键代码:"metaData":{"customizeData":[{"name":"EasyGoClient","value":"true"}]}中src->main->resources->rawfile目录下添加easygo.json配置文件:{"easyGoVersion":"1.0","client":"com.test.mydemo3","logicEntities":[{"head":{“function”:“magicwindow”,“required”:“true”},“body”:{“mode”:“0”,“transActivities”:[“com.test.mydemo3.NavigationAbility”,“com.test.mydemo3.FirstAbility","com.test.mydemo3.SecondAbility"],"能力":[{"name":"com.test.mydemo3.MainAbility","defaultFullScreen":"false"},{"name":"com.test.mydemo3.NavigationAbility","defaultFullScreen":"false"},{"name":"com.test.mydemo3.FirstAbility","defaultFullScreen":"false"},{"name":"com.test.mydemo3.SecondAbility","defaultFullScreen":"false"},{"name":"com.test.mydemo3.ThridAbility""defaultFullScreen":"false"}],"UX":{"isDraggable":"true","supportLock":"true"}}}]}上面代码easygo.json配置的相关元素说明文件如下:{"easyGoVersion":"client":"logicEntities":[{"head":{"function":"required":},"body":{"mode":0":购物模式,"transActivities":[Transitionpagelist],"Abilities":[{"name":"defaultFullScreen":}],"UX":{"isDraggable":"supportLock":,可选,是否支持应用内用户lockfunction."true":支持lock,;,"false":不支持(默认值为false)}}}]}运行效果tabletlandscape运行效果如下:总结购物模式可以有效解决宽屏设备显示适配问题,适用场景及购物应用。从上面的运行结果我们可以发现,购物模式具有三个特点:1、点击左边,点击右边。2、点击右边的开始新窗口,将当前内容推到左边,右边显示新内容。3、当左侧触发返回时,左右窗口界面会退出上一级或首页;如果在右侧触发返回,则右侧窗口将返回上一级,不影响左侧页面。后台锁在应用中开启并行水平后,可以在适合多任务并行/多任务并行需求的特定场景下使用后台锁。可以通过如下配置:"UX":{"supportLock":"true"}双窗口显示状态会显示一个锁定按钮,用户点击后可以进行锁定和解锁操作;锁定后,左右窗口不再关联,即左侧显示打开新窗口,右侧显示打开新窗口。例如,在普通购物模式下,点击右侧屏幕的内容会将右侧的内容推送到左侧;直播场景锁定后,直播会固定在左侧显示,点击右侧内容会改变右侧显示的内容。其他{"easyGoVersion":,"client":,"logicEntities":[{"head":{"function":,"required":},"body":{"mode":"0","abilityPairs":[{"from":,"to":}],"defaultDualAbilities":{可选,冷启动时应用默认打开双屏配置的首页"mainPages":PageAbility包名,冷启动时应用程序打开该页面,系统会在左屏自动启动该页面,"relatedPage":PageAbility包名,当冷启动应用打开该页面时,系统会自动在右屏启动该页面},"transActivities":[],"Abilities":[{"name":,"defaultFullScreen":}],"UX":{"supportRotationUxCompat":可选,是否启用窗口缩放,用于提高屏幕旋转应用的UX显示兼容性(仅适用于平板电脑产品)。"true":支持;"false":不支持(默认为false),"isDraggable":,"supportVideoFullscreen":可选,是否支持视频全屏(仅对平板产品有效)。“真”:支持;"false":不支持(默认值为false),"supportDraggingToFullScreen":可选,是否支持分屏和全屏拖动。“ALL”:所有设备都支持该功能;“PAD”:该功能仅在平板产品上支持;"FOLD":该功能仅在折叠屏上支持,"supportLock":}}}]}更多内容请访问:https://harmonyos.51cto.com,与华为官方共同打造的鸿蒙技术社区
