HarmonyOS鸿蒙Next中如何实现横竖屏旋转策略跟随系统自动判断显示
HarmonyOS鸿蒙Next中如何实现横竖屏旋转策略跟随系统自动判断显示 在工程的Moudle.json5配置文件中,已经设置了"orientation": “unspecified”。但是在手机未锁定屏幕,且手机已经横屏的情况下,APP还是竖屏显示。
还需哪些其他配置吗?
"如果应用为可旋转应用,建议应用配置auto_rotation_restricted为默认旋转策略。
下面链接是横竖屏开发的具体介绍
Scroll是当子组件的布局尺寸超过父组件的尺寸时,内容可以滚动,和横竖屏无关,关键是看子组件是否超出父组件尺寸,
RelativeContainer设置高度如果父组件高度小也不会有滑动效果
鸿蒙提供的各种滚动滑动资料如下,如果只是内容展示不全需要滑动使用Scroll即可
你可以修改如下demo里的高度值看不同情况下的效果
```less @Entry @Component struct Index { scroller: Scroller = new Scroller() build() { Scroll(this.scroller) { Row() { RelativeContainer() { Row() { Text(‘row1’) } .justifyContent(FlexAlign.Center) .width(100) .height(100) .backgroundColor("#FF3333") .alignRules({ top: { anchor: “container”, align: VerticalAlign.Top }, left: { anchor: “container”, align: HorizontalAlign.Start } }) .id(“row1”) Row() { Text(‘row2’) } .justifyContent(FlexAlign.Center) .width(100) .height(100) .backgroundColor("#FFCC00") .alignRules({ top: { anchor: “container”, align: VerticalAlign.Top }, right: { anchor: “container”, align: HorizontalAlign.End } }) .id(“row2”) Row() { Text(‘row3’) } .justifyContent(FlexAlign.Center) .height(100) .backgroundColor("#FF6633") .alignRules({ top: { anchor: “row1”, align: VerticalAlign.Bottom }, left: { anchor: “row1”, align: HorizontalAlign.End }, right: { anchor: “row2”, align: HorizontalAlign.Start } }) .id(“row3”) Row() { Text(‘row4’) }.justifyContent(FlexAlign.Center) .backgroundColor("#FF9966") .alignRules({ top: { anchor: “row3”, align: VerticalAlign.Bottom }, bottom: { anchor: “container”, align: VerticalAlign.Bottom }, left: { anchor: “container”, align: HorizontalAlign.Start }, right: { anchor: “row1”, align: HorizontalAlign.End } }) .id(“row4”) Row() { Text(‘row5’) }.justifyContent(FlexAlign.Center) .backgroundColor("#FF66FF") .alignRules({ top: { anchor: “row3”, align: VerticalAlign.Bottom }, bottom: { anchor: “container”, align: VerticalAlign.Bottom }, left: { anchor: “row2”, align: HorizontalAlign.Start }, right: { anchor: “container”, align: HorizontalAlign.End } }) .id(“row5”) } .border({ width: 0, color: “#6699FF” }) .height(500) } } .height(300) } } ```
更多关于HarmonyOS鸿蒙Next中如何实现横竖屏旋转策略跟随系统自动判断显示的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next中,实现横竖屏旋转策略跟随系统自动判断显示,可以通过配置config.json
文件中的orientation
属性来实现。具体步骤如下:
- 打开项目的
config.json
文件。 - 在
config.json
文件中找到"module"
节点下的"abilities"
数组。 - 在
"abilities"
数组中,找到需要配置的Ability节点。 - 在该Ability节点中,添加或修改
"orientation"
属性,将其值设置为"unspecified"
。
示例配置如下:
"abilities": [
{
"name": ".MainAbility",
"orientation": "unspecified"
}
]
将"orientation"
属性设置为"unspecified"
后,应用将根据系统的横竖屏设置自动调整显示方向,无需手动干预。
在HarmonyOS鸿蒙Next中,实现横竖屏旋转策略跟随系统自动判断显示,可以通过设置orientation
属性来实现。在config.json
文件中,为每个页面或应用配置"orientation": "auto"
,这样系统会根据设备的方向自动调整显示模式。同时,确保在代码中处理onConfigurationChanged
事件,以响应屏幕方向变化,动态调整UI布局。