Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
0f3c9f72
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0f3c9f72
编写于
9月 05, 2023
作者:
O
openharmony_ci
提交者:
Gitee
9月 05, 2023
浏览文件
操作
浏览文件
下载
差异文件
!23863 【master】一多akrts整改
Merge pull request !23863 from songqq0825/master
上级
2a7eff05
4bda3432
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
80 addition
and
60 deletion
+80
-60
zh-cn/application-dev/key-features/multi-device-app-dev/faq.md
.../application-dev/key-features/multi-device-app-dev/faq.md
+2
-1
zh-cn/application-dev/key-features/multi-device-app-dev/responsive-layout.md
...ev/key-features/multi-device-app-dev/responsive-layout.md
+78
-59
未找到文件。
zh-cn/application-dev/key-features/multi-device-app-dev/faq.md
浏览文件 @
0f3c9f72
...
...
@@ -96,6 +96,7 @@ launchType字段配置为specified时,系统会根据AbilityStage的onAcceptWa
// MyAbilityStage.ts
import
AbilityStage
from
"
@ohos.app.ability.AbilityStage
"
import
deviceInfo
from
'
@ohos.deviceInfo
'
import
Want
from
'
@ohos.app.ability.Want
'
export
default
class
MyAbilityStage
extends
AbilityStage
{
...
...
...
@@ -107,7 +108,7 @@ export default class MyAbilityStage extends AbilityStage {
// 如果不是平板,直接以设备类型作为key,每次启动的key相同
return
deviceInfo
.
deviceType
}
onAcceptWant
(
want
)
{
onAcceptWant
(
want
:
Want
)
:
string
{
return
this
.
generateKey
()
}
}
...
...
zh-cn/application-dev/key-features/multi-device-app-dev/responsive-layout.md
浏览文件 @
0f3c9f72
...
...
@@ -52,15 +52,16 @@
```
ts
// MainAbility.ts
import
window
from
'
@ohos.window
'
import
type
window
from
'
@ohos.window
'
import
display
from
'
@ohos.display
'
import
Ability
from
'
@ohos.app.ability.Ability
'
export
default
class
MainAbility
extends
Ability
{
private
windowObj
:
window
.
Window
private
curBp
:
string
...
//
...
// 根据当前窗口尺寸更新断点
private
updateBreakpoint
(
windowWidth
)
{
private
updateBreakpoint
(
windowWidth
)
:
void
{
// 将长度的单位由px换算为vp
let
windowWidthVp
=
windowWidth
/
(
display
.
getDefaultDisplaySync
().
densityDPI
/
160
)
let
newBp
:
string
=
''
...
...
@@ -80,7 +81,7 @@
}
}
onWindowStageCreate
(
windowStage
:
window
.
WindowStage
)
{
onWindowStageCreate
(
windowStage
:
window
.
WindowStage
)
:
void
{
windowStage
.
getMainWindow
().
then
((
windowObj
)
=>
{
this
.
windowObj
=
windowObj
// 获取应用启动时的窗口尺寸
...
...
@@ -90,16 +91,16 @@
this
.
updateBreakpoint
(
windowSize
.
width
)
})
});
...
//
...
}
// 窗口销毁时,取消窗口尺寸变化监听
onWindowStageDestroy
()
{
onWindowStageDestroy
()
:
void
{
if
(
this
.
windowObj
)
{
this
.
windowObj
.
off
(
'
windowSizeChange
'
)
}
}
...
//
...
}
```
...
...
@@ -165,7 +166,7 @@ export class BreakpointType<T> {
this
.
md
=
md
this
.
lg
=
lg
}
GetValue
(
currentBreakpoint
:
string
)
{
GetValue
(
currentBreakpoint
:
string
)
:
T
{
if
(
currentBreakpoint
===
'
sm
'
)
{
return
this
.
sm
}
...
...
@@ -185,29 +186,29 @@ export class BreakpointSystem {
private
mdListener
:
mediaquery
.
MediaQueryListener
private
lgListener
:
mediaquery
.
MediaQueryListener
private
updateCurrentBreakpoint
(
breakpoint
:
string
)
{
private
updateCurrentBreakpoint
(
breakpoint
:
string
)
:
void
{
if
(
this
.
currentBreakpoint
!==
breakpoint
)
{
this
.
currentBreakpoint
=
breakpoint
AppStorage
.
Set
<
string
>
(
'
currentBreakpoint
'
,
this
.
currentBreakpoint
)
}
}
private
isBreakpointSM
=
(
mediaQueryResult
)
=>
{
private
isBreakpointSM
=
(
mediaQueryResult
:
mediaquery
.
MediaQueryResult
)
:
void
=>
{
if
(
mediaQueryResult
.
matches
)
{
this
.
updateCurrentBreakpoint
(
'
sm
'
)
}
}
private
isBreakpointMD
=
(
mediaQueryResult
)
=>
{
private
isBreakpointMD
=
(
mediaQueryResult
:
mediaquery
.
MediaQueryResult
)
:
void
=>
{
if
(
mediaQueryResult
.
matches
)
{
this
.
updateCurrentBreakpoint
(
'
md
'
)
}
}
private
isBreakpointLG
=
(
mediaQueryResult
)
=>
{
private
isBreakpointLG
=
(
mediaQueryResult
:
mediaquery
.
MediaQueryResult
):
void
=>
{
if
(
mediaQueryResult
.
matches
)
{
this
.
updateCurrentBreakpoint
(
'
lg
'
)
}
}
public
register
()
{
public
register
()
:
void
{
this
.
smListener
=
mediaquery
.
matchMediaSync
(
"
(320vp<width<600vp)
"
)
//初始化
if
(
this
.
smListener
.
matches
){
...
...
@@ -215,20 +216,20 @@ export class BreakpointSystem {
}
this
.
smListener
.
on
(
"
change
"
,
this
.
isBreakpointSM
)
this
.
mdListener
=
mediaquery
.
matchMediaSync
(
"
(600vp<width<840vp)
"
)
//初始化
//初始化
if
(
this
.
mdListener
.
matches
){
this
.
updateCurrentBreakpoint
(
'
md
'
)
}
this
.
mdListener
.
on
(
"
change
"
,
this
.
isBreakpointMD
)
this
.
lgListener
=
mediaquery
.
matchMediaSync
(
"
(840vp<width)
"
)
//初始化
//初始化
if
(
this
.
lgListener
.
matches
){
this
.
updateCurrentBreakpoint
(
'
lg
'
)
}
this
.
lgListener
.
on
(
"
change
"
,
this
.
isBreakpointLG
)
}
public
unregister
()
{
public
unregister
()
:
void
{
this
.
smListener
.
off
(
"
change
"
,
this
.
isBreakpointSM
)
this
.
mdListener
.
off
(
"
change
"
,
this
.
isBreakpointMD
)
this
.
lgListener
.
off
(
"
change
"
,
this
.
isBreakpointLG
)
...
...
@@ -441,7 +442,7 @@ struct GridRowSample3 {
// 配置不同断点下columns和gutter的取值
GridRow
({
columns
:
{
sm
:
4
,
md
:
8
,
lg
:
12
},
gutter
:
{
x
:
{
sm
:
8
,
md
:
16
,
lg
:
24
},
y
:
{
sm
:
8
,
md
:
16
,
lg
:
24
}}})
{
ForEach
(
this
.
bgColors
,
(
bgColor
)
=>
{
ForEach
(
this
.
bgColors
,
(
bgColor
:
ResourceColor
)
=>
{
GridCol
({
span
:
{
sm
:
2
,
md
:
2
,
lg
:
2
}})
{
Row
().
backgroundColor
(
bgColor
).
height
(
30
).
width
(
'
100%
'
)
}
...
...
@@ -538,21 +539,25 @@ struct GridRowSample4 {
```
ts
class
Obj
{
public
index
:
number
=
1
;
public
color
:
Resource
=
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)
}
@
Entry
@
Component
struct
GridRowSample5
{
private
elements
:
Obj
ect
[]
=
[
{
'
index
'
:
1
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
'
index
'
:
2
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
'
index
'
:
3
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
'
index
'
:
4
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
'
index
'
:
5
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
'
index
'
:
6
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
private
elements
:
Obj
[]
=
[
{
index
:
1
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
index
:
2
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
index
:
3
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
index
:
4
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
index
:
5
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
index
:
6
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
]
build
()
{
GridRow
()
{
ForEach
(
this
.
elements
,
(
item
)
=>
{
ForEach
(
this
.
elements
,
(
item
:
Obj
)
=>
{
GridCol
({
span
:
{
sm
:
6
,
md
:
(
item
.
index
%
3
===
0
)
?
0
:
4
,
lg
:
3
}})
{
Row
()
{
Text
(
''
+
item
.
index
).
fontSize
(
24
)
...
...
@@ -580,21 +585,25 @@ struct GridRowSample5 {
```
ts
class
Obj
{
public
index
:
number
=
1
;
public
color
:
Resource
=
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)
}
@
Entry
@
Component
struct
GridRowSample6
{
private
elements
:
Obj
ect
[]
=
[
{
'
index
'
:
1
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
'
index
'
:
2
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
'
index
'
:
3
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
'
index
'
:
4
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
'
index
'
:
5
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
'
index
'
:
6
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
private
elements
:
Obj
[]
=
[
{
index
:
1
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
index
:
2
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
index
:
3
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
index
:
4
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
index
:
5
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
index
:
6
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
]
build
()
{
GridRow
()
{
ForEach
(
this
.
elements
,
(
item
)
=>
{
ForEach
(
this
.
elements
,
(
item
:
Obj
)
=>
{
GridCol
({
span
:
{
sm
:
6
,
md
:
4
,
lg
:
3
},
offset
:
{
sm
:
0
,
md
:
2
,
lg
:
1
}
})
{
Row
()
{
Text
(
''
+
item
.
index
).
fontSize
(
24
)
...
...
@@ -622,21 +631,25 @@ struct GridRowSample6 {
```
ts
class
Obj
{
public
index
:
number
=
1
;
public
color
:
Resource
=
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)
}
@
Entry
@
Component
struct
GridRowSample7
{
private
elements
:
Obj
ect
[]
=
[
{
'
index
'
:
1
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
'
index
'
:
2
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
'
index
'
:
3
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
'
index
'
:
4
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
'
index
'
:
5
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
'
index
'
:
6
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
private
elements
:
Obj
[]
=
[
{
index
:
1
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
index
:
2
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
index
:
3
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
index
:
4
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
index
:
5
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
index
:
6
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
]
build
()
{
GridRow
()
{
ForEach
(
this
.
elements
,
(
item
)
=>
{
ForEach
(
this
.
elements
,
(
item
:
Obj
)
=>
{
GridCol
({
span
:
{
sm
:
6
,
md
:
4
,
lg
:
3
},
order
:
{
lg
:
(
6
-
item
.
index
)}})
{
Row
()
{
Text
(
''
+
item
.
index
).
fontSize
(
24
)
...
...
@@ -664,21 +677,24 @@ struct GridRowSample7 {
```
ts
class
Obj
{
public
index
:
number
=
1
;
public
color
:
Resource
=
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)
}
@
Entry
@
Component
struct
GridRowSample8
{
private
elements
:
Obj
ect
[]
=
[
{
'
index
'
:
1
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
'
index
'
:
2
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
'
index
'
:
3
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
'
index
'
:
4
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
'
index
'
:
5
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
'
index
'
:
6
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
private
elements
:
Obj
[]
=
[
{
index
:
1
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
index
:
2
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
index
:
3
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
index
:
4
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
index
:
5
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
index
:
6
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
]
build
()
{
GridRow
()
{
ForEach
(
this
.
elements
,
(
item
)
=>
{
ForEach
(
this
.
elements
,
(
item
:
Obj
)
=>
{
// 不配置md断点下三个参数的值,则其取值与sm断点相同
GridCol
({
span
:
{
sm
:
4
,
lg
:
3
},
offset
:
{
sm
:
2
,
lg
:
1
},
order
:
{
sm
:
(
6
-
item
.
index
),
lg
:
item
.
index
}})
{
...
...
@@ -707,23 +723,26 @@ struct GridRowSample8 {
```
ts
class
Obj
{
public
index
:
number
=
1
;
public
color
:
Resource
=
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)
}
@
Entry
@
Component
struct
GridRowSample9
{
private
elements
:
Obj
ect
[]
=
[
{
'
index
'
:
1
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
'
index
'
:
2
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
'
index
'
:
3
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
'
index
'
:
4
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
'
index
'
:
5
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
'
index
'
:
6
,
'
color
'
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
private
elements
:
Obj
[]
=
[
{
index
:
1
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux1
'
)},
{
index
:
2
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux2
'
)},
{
index
:
3
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux3
'
)},
{
index
:
4
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux4
'
)},
{
index
:
5
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux5
'
)},
{
index
:
6
,
color
:
$r
(
'
sys.color.ohos_id_color_palette_aux6
'
)},
]
build
()
{
GridRow
()
{
GridCol
({
span
:
{
sm
:
12
,
md
:
10
,
lg
:
8
},
offset
:
{
sm
:
0
,
md
:
1
,
lg
:
2
}})
{
GridRow
()
{
ForEach
(
this
.
elements
,
(
item
)
=>
{
ForEach
(
this
.
elements
,
(
item
:
Obj
)
=>
{
GridCol
({
span
:
{
sm
:
6
,
md
:
4
,
lg
:
3
}})
{
Row
()
{
Text
(
''
+
item
.
index
).
fontSize
(
24
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录