提交 05369443 编写于 作者: S sienna1128

update docs

Signed-off-by: Nsienna1128 <lixiaoyan45@huawei.com>
上级 4f2d6243
...@@ -32,7 +32,8 @@ Blank(min?: number&nbsp;|&nbsp;string) ...@@ -32,7 +32,8 @@ Blank(min?: number&nbsp;|&nbsp;string)
## 示例 ## 示例
### 示例1
Blank组件在横竖屏占满空余空间效果。
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
...@@ -57,3 +58,37 @@ struct BlankExample { ...@@ -57,3 +58,37 @@ struct BlankExample {
横屏状态 横屏状态
![zh-cn_image_0000001174104388](figures/zh-cn_image_0000001174104388.gif) ![zh-cn_image_0000001174104388](figures/zh-cn_image_0000001174104388.gif)
### 示例2
Blank组件的父组件未设置宽度时,min参数的使用效果。
```ts
// xxx.ets
@Entry
@Component
struct BlankExample {
build() {
Column({ space: 20 }) {
// blank父组件不设置宽度时,Blank失效,可以通过设置min最小宽度填充固定宽度
Row() {
Text('Bluetooth').fontSize(18)
Blank().color(Color.Yellow)
Toggle({ type: ToggleType.Switch })
}.backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 })
Row() {
Text('Bluetooth').fontSize(18)
// 设置最小宽度为160
Blank('160').color(Color.Yellow)
Toggle({ type: ToggleType.Switch })
}.backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 })
}.backgroundColor(0xEFEFEF).padding(20).width('100%')
}
}
```
Blank父组件未设置宽度时,子组件间无空白填充,使用min参数设置填充尺寸
![blankmin](figures/blankmin.png)
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
CheckboxGroup(options?: { group?: string }) CheckboxGroup(options?: { group?: string })
创建多选框群组,可以控制群组内的Checkbox全选或者不全选,相同group的Checkbox和CheckboxGroup为同一群组。 创建多选框群组,可以控制群组内的Checkbox全选或者不全选,group值相同的Checkbox和CheckboxGroup为同一群组。
**参数:** **参数:**
...@@ -39,13 +39,13 @@ CheckboxGroup(options?: { group?: string }) ...@@ -39,13 +39,13 @@ CheckboxGroup(options?: { group?: string })
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onChange (callback: (event: CheckboxGroupResult) => void ) |CheckboxGroup的选中状态或群组内的Checkbox的选中状态发生变化时,触发回调。| | onChange (callback: (event: [CheckboxGroupResult](#checkboxgroupresult对象说明)) => void ) |CheckboxGroup的选中状态或群组内的Checkbox的选中状态发生变化时,触发回调。|
## CheckboxGroupResult对象说明 ## CheckboxGroupResult对象说明
| 名称 | 类型 | 描述 | | 名称 | 类型 | 描述 |
| ------ | ------ | ------- | | ------ | ------ | ------- |
| name | Array&lt;string&gt; | 群组内所有被选中的多选框名称。 | | name | Array&lt;string&gt; | 群组内所有被选中的多选框名称。 |
| status | SelectStatus | 选中状态。 | | status | [SelectStatus](#selectstatus枚举说明) | 选中状态。 |
## SelectStatus枚举说明 ## SelectStatus枚举说明
...@@ -66,18 +66,19 @@ struct CheckboxExample { ...@@ -66,18 +66,19 @@ struct CheckboxExample {
build() { build() {
Scroll() { Scroll() {
Column() { Column() {
// 全选按钮
Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
CheckboxGroup({ group: 'checkboxGroup' }) CheckboxGroup({ group: 'checkboxGroup' })
.selectedColor(0xed6f21) .selectedColor(0xed6f21)
.onChange((itemName: CheckboxGroupResult) => { .onChange((itemName: CheckboxGroupResult) => {
console.info("TextPicker::dialogResult is" + JSON.stringify(itemName)) console.info("checkbox group content" + JSON.stringify(itemName))
}) })
Text('select all').fontSize(20) Text('Select All').fontSize(20)
} }
// 选项1
Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
Checkbox({ name: 'checkbox1', group: 'checkboxGroup' }) Checkbox({ name: 'checkbox1', group: 'checkboxGroup' })
.select(true)
.selectedColor(0x39a2db) .selectedColor(0x39a2db)
.onChange((value: boolean) => { .onChange((value: boolean) => {
console.info('Checkbox1 change is' + value) console.info('Checkbox1 change is' + value)
...@@ -85,9 +86,9 @@ struct CheckboxExample { ...@@ -85,9 +86,9 @@ struct CheckboxExample {
Text('Checkbox1').fontSize(20) Text('Checkbox1').fontSize(20)
} }
// 选项2
Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
Checkbox({ name: 'checkbox2', group: 'checkboxGroup' }) Checkbox({ name: 'checkbox2', group: 'checkboxGroup' })
.select(false)
.selectedColor(0x39a2db) .selectedColor(0x39a2db)
.onChange((value: boolean) => { .onChange((value: boolean) => {
console.info('Checkbox2 change is' + value) console.info('Checkbox2 change is' + value)
...@@ -95,9 +96,9 @@ struct CheckboxExample { ...@@ -95,9 +96,9 @@ struct CheckboxExample {
Text('Checkbox2').fontSize(20) Text('Checkbox2').fontSize(20)
} }
// 选项3
Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
Checkbox({ name: 'checkbox3', group: 'checkboxGroup' }) Checkbox({ name: 'checkbox3', group: 'checkboxGroup' })
.select(true)
.selectedColor(0x39a2db) .selectedColor(0x39a2db)
.onChange((value: boolean) => { .onChange((value: boolean) => {
console.info('Checkbox3 change is' + value) console.info('Checkbox3 change is' + value)
...@@ -109,4 +110,10 @@ struct CheckboxExample { ...@@ -109,4 +110,10 @@ struct CheckboxExample {
} }
} }
``` ```
![](figures/checkboxgroup.gif) 多选框组三种状态图示:
![](figures/checkboxgroup1.png)
![](figures/checkboxgroup2.png)
![](figures/checkboxgroup3.png)
...@@ -24,7 +24,7 @@ DataPanel(options:{values: number[], max?: number, type?: DataPanelType}) ...@@ -24,7 +24,7 @@ DataPanel(options:{values: number[], max?: number, type?: DataPanelType})
| ----------------- | -------- | ----- | -------- | | ----------------- | -------- | ----- | -------- |
| values | number[] | 是 | 数据值列表,最大支持9个数据。 | | values | number[] | 是 | 数据值列表,最大支持9个数据。 |
| max | number | 否 | -&nbsp;max大于0,表示数据的最大值。<br/>-&nbsp;max小于等于0,max等于value数组各项的和,按比例显示。<br/>默认值:100 | | max | number | 否 | -&nbsp;max大于0,表示数据的最大值。<br/>-&nbsp;max小于等于0,max等于value数组各项的和,按比例显示。<br/>默认值:100 |
| type<sup>8+</sup> | DataPanelType | 否 | 数据面板的类型。<br/>默认值:DataPanelType.Circle | | type<sup>8+</sup> | [DataPanelType](#datapaneltype枚举说明) | 否 | 数据面板的类型。<br/>默认值:DataPanelType.Circle |
## DataPanelType枚举说明 ## DataPanelType枚举说明
......
...@@ -47,6 +47,7 @@ struct DividerExample { ...@@ -47,6 +47,7 @@ struct DividerExample {
Divider() Divider()
Row().width('100%').height(40).backgroundColor(0xF1F3F5) Row().width('100%').height(40).backgroundColor(0xF1F3F5)
// 纵向分割线
Text('Vertical divider').fontSize(9).fontColor(0xCCCCCC) Text('Vertical divider').fontSize(9).fontColor(0xCCCCCC)
Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.Wrap }) { Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.Wrap }) {
Text('bravery') Text('bravery')
...@@ -56,6 +57,7 @@ struct DividerExample { ...@@ -56,6 +57,7 @@ struct DividerExample {
Text('upward') Text('upward')
}.width(250) }.width(250)
// 设置分割线宽度和端点样式
Text('Custom Styles').fontSize(9).fontColor(0xCCCCCC) Text('Custom Styles').fontSize(9).fontColor(0xCCCCCC)
Row().width('100%').height(40).backgroundColor(0xF1F3F5) Row().width('100%').height(40).backgroundColor(0xF1F3F5)
Divider().vertical(false).strokeWidth(5).color(0x2788D9).lineCap(LineCapStyle.Round) Divider().vertical(false).strokeWidth(5).color(0x2788D9).lineCap(LineCapStyle.Round)
......
...@@ -21,7 +21,7 @@ Gauge(options:{value: number, min?: number, max?: number}) ...@@ -21,7 +21,7 @@ Gauge(options:{value: number, min?: number, max?: number})
| 参数名 | 参数类型 | 必填 | 参数描述 | | 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | number | 是 | 当前数据值。 | | value | number | 是 | 量规图的当前数据值,即图中指针指向位置。用于组件创建时量规图初始值的预置。 |
| min | number | 否 | 当前数据段最小值。<br/>默认值:0 | | min | number | 否 | 当前数据段最小值。<br/>默认值:0 |
| max | number | 否 | 当前数据段最大值。<br/>默认值:100 | | max | number | 否 | 当前数据段最大值。<br/>默认值:100 |
...@@ -31,11 +31,11 @@ Gauge(options:{value: number, min?: number, max?: number}) ...@@ -31,11 +31,11 @@ Gauge(options:{value: number, min?: number, max?: number})
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| value | number | 设置当前数据图表的值。<br/>默认值:0 | | value | number | 设置量规图的数据值,可用于动态修改量规图的数据值。<br/>默认值:0 |
| startAngle | number | 设置起始角度位置,时钟0点为0度,顺时针方向为正角度。<br/>默认值:-150 | | startAngle | number | 设置起始角度位置,时钟0点为0度,顺时针方向为正角度。<br/>默认值:0 |
| endAngle | number | 设置终止角度位置,时钟0点为0度,顺时针方向为正角度。<br/>默认值:150 | | endAngle | number | 设置终止角度位置,时钟0点为0度,顺时针方向为正角度。<br/>默认值:360 |
| colors | Array&lt;ColorStop&gt; | 设置图表的颜色,支持分段颜色设置。 | | colors | Array&lt;[ColorStop](#colorstop)&gt; | 设置量规图的颜色,支持分段颜色设置。 |
| strokeWidth | Length | 设置环形图表的环形厚度。 | | strokeWidth | Length | 设置环形量规图的环形厚度。 |
## ColorStop ## ColorStop
...@@ -55,15 +55,30 @@ Gauge(options:{value: number, min?: number, max?: number}) ...@@ -55,15 +55,30 @@ Gauge(options:{value: number, min?: number, max?: number})
@Component @Component
struct GaugeExample { struct GaugeExample {
build() { build() {
Column() { Column({ space: 20 }) {
Gauge({ value: 50, min: 0, max: 100 }) // 使用默认的min和max为0-100,角度范围默认0-360,value值设置
.startAngle(210).endAngle(150) // 参数中设置当前值为75
.colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1], [0xD94838, 1]]) Gauge({ value: 75 })
.strokeWidth(20) .width(200).height(200)
.colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1]])
// 参数设置当前值为75,属性设置值为25,属性设置优先级高
Gauge({ value: 75 })
.value(25) //属性和参数都设置时以参数为准
.width(200).height(200) .width(200).height(200)
.colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1]])
// 210--150度环形图表
Gauge({ value: 30, min: 0, max: 100 })
.startAngle(210)
.endAngle(150)
.colors([[0x317AF7, 0.1], [0x5BA854, 0.2], [0xE08C3A, 0.3], [0x9C554B, 0.4]])
.strokeWidth(20)
.width(200)
.height(200)
}.width('100%').margin({ top: 5 }) }.width('100%').margin({ top: 5 })
} }
} }
``` ```
![zh-cn_image_0000001174422916](figures/zh-cn_image_0000001174422916.png) ![gauge](figures/gauge-image.png)
...@@ -26,12 +26,12 @@ Navigation() ...@@ -26,12 +26,12 @@ Navigation()
| -------------- | ---------------------------------------- | ---------------------------------------- | | -------------- | ---------------------------------------- | ---------------------------------------- |
| title | string&nbsp;\|&nbsp;[CustomBuilder](ts-types.md#custombuilder8)<sup>8+</sup> | 页面标题。 | | title | string&nbsp;\|&nbsp;[CustomBuilder](ts-types.md#custombuilder8)<sup>8+</sup> | 页面标题。 |
| subTitle | string | 页面副标题。 | | subTitle | string | 页面副标题。 |
| menus | Array<NavigationMenuItem&gt;&nbsp;\|&nbsp;[CustomBuilder](ts-types.md#custombuilder8)<sup>8+</sup> | 页面右上角菜单。 | | menus | Array<[NavigationMenuItem](#navigationmenuitem类型说明)&gt;&nbsp;\|&nbsp;[CustomBuilder](ts-types.md#custombuilder8)<sup>8+</sup> | 页面右上角菜单。 |
| titleMode | NavigationTitleMode | 页面标题栏显示模式。<br/>默认值:NavigationTitleMode.Free | | titleMode | [NavigationTitleMode](#navigationtitlemode枚举说明) | 页面标题栏显示模式。<br/>默认值:NavigationTitleMode.Free |
| toolBar | object&nbsp;\|&nbsp;[CustomBuilder](ts-types.md#custombuilder8)<sup>8+</sup> | 设置工具栏内容。<br/>items:&nbsp;工具栏所有项。 | | toolBar | [object](#object类型说明)&nbsp;\|&nbsp;[CustomBuilder](ts-types.md#custombuilder8)<sup>8+</sup> | 设置工具栏内容。<br/>items:&nbsp;工具栏所有项。 |
| hideToolBar | boolean | 设置隐藏/显示工具栏:<br/>默认值:false<br/>true:&nbsp;隐藏工具栏。<br/>false:&nbsp;显示工具栏。 | | hideToolBar | boolean | 隐藏工具栏:<br/>默认值:false<br/>true:&nbsp;隐藏工具栏。<br/>false:&nbsp;显示工具栏。 |
| hideTitleBar | boolean | 隐藏标题栏。<br/>默认值:false | | hideTitleBar | boolean | 隐藏标题栏。<br/>默认值:false<br/>true:&nbsp;隐藏标题栏。<br/>false:&nbsp;显示标题栏。 |
| hideBackButton | boolean | 隐藏返回键。<br/>默认值:false | | hideBackButton | boolean | 隐藏返回键。<br/>默认值:false<br/>true:&nbsp;隐藏返回键。<br/>false:&nbsp;显示返回键。 |
## NavigationMenuItem类型说明 ## NavigationMenuItem类型说明
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
## 接口说明 ## 接口
Progress(options: {value: number, total?: number, type?: ProgressType}) Progress(options: {value: number, total?: number, type?: ProgressType})
...@@ -24,8 +24,8 @@ Progress(options: {value: number, total?: number, type?: ProgressType}) ...@@ -24,8 +24,8 @@ Progress(options: {value: number, total?: number, type?: ProgressType})
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | number | 是 | 指定当前进度值。 | | value | number | 是 | 指定当前进度值。 |
| total | number | 否 | 指定进度总长。<br/>默认值:100 | | total | number | 否 | 指定进度总长。<br/>默认值:100 |
| type<sup>8+</sup> | ProgressType | 否 | 指定进度条样式<br/>默认值:ProgressType.Linear | | type<sup>8+</sup> | [ProgressType](#progresstype枚举说明) | 否 | 指定进度条类型<br/>默认值:ProgressType.Linear |
| style<sup>deprecated</sup> | ProgressStyle | 否 | 指定进度条类型<br/>该参数从API Version8开始废弃,建议使用type替代。<br/>默认值:ProgressStyle.Linear | | style<sup>deprecated</sup> | [ProgressStyle](#progressstyle枚举说明) | 否 | 指定进度条样式<br/>该参数从API Version8开始废弃,建议使用type替代。<br/>默认值:ProgressStyle.Linear |
## ProgressType枚举说明 ## ProgressType枚举说明
...@@ -69,6 +69,7 @@ struct ProgressExample { ...@@ -69,6 +69,7 @@ struct ProgressExample {
Progress({ value: 10, type: ProgressType.Linear }).width(200) Progress({ value: 10, type: ProgressType.Linear }).width(200)
Progress({ value: 20, total: 150, type: ProgressType.Linear }).color(Color.Grey).value(50).width(200) Progress({ value: 20, total: 150, type: ProgressType.Linear }).color(Color.Grey).value(50).width(200)
Text('Eclipse Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('Eclipse Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row({ space: 40 }) { Row({ space: 40 }) {
Progress({ value: 10, type: ProgressType.Eclipse }).width(100) Progress({ value: 10, type: ProgressType.Eclipse }).width(100)
...@@ -83,6 +84,16 @@ struct ProgressExample { ...@@ -83,6 +84,16 @@ struct ProgressExample {
.style({ strokeWidth: 15, scaleCount: 15, scaleWidth: 5 }) .style({ strokeWidth: 15, scaleCount: 15, scaleWidth: 5 })
} }
// scaleCount和scaleWidth效果对比
Row({ space: 40 }) {
Progress({ value: 20, total: 150, type: ProgressType.ScaleRing })
.color(Color.Grey).value(50).width(100)
.style({ strokeWidth: 20, scaleCount: 20, scaleWidth: 5 })
Progress({ value: 20, total: 150, type: ProgressType.ScaleRing })
.color(Color.Grey).value(50).width(100)
.style({ strokeWidth: 20, scaleCount: 30, scaleWidth: 3 })
}
Text('Ring Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('Ring Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row({ space: 40 }) { Row({ space: 40 }) {
Progress({ value: 10, type: ProgressType.Ring }).width(100) Progress({ value: 10, type: ProgressType.Ring }).width(100)
...@@ -105,4 +116,4 @@ struct ProgressExample { ...@@ -105,4 +116,4 @@ struct ProgressExample {
} }
``` ```
![zh-cn_image_0000001198839004](figures/zh-cn_image_0000001198839004.gif) ![progress](figures/progress.png)
...@@ -44,17 +44,21 @@ QRCode(value: string) ...@@ -44,17 +44,21 @@ QRCode(value: string)
@Component @Component
struct QRCodeExample { struct QRCodeExample {
private value: string = 'hello world' private value: string = 'hello world'
build() { build() {
Column({ space: 5 }) { Column({ space: 5 }) {
Text('normal').fontSize(9).width('90%').fontColor(0xCCCCCC) Text('normal').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30)
QRCode(this.value).width(200).height(200) QRCode(this.value).width(200).height(200)
Text('color').fontSize(9).width('90%').fontColor(0xCCCCCC) // 设置二维码颜色
Text('color').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30)
QRCode(this.value).color(0xF7CE00).width(200).height(200) QRCode(this.value).color(0xF7CE00).width(200).height(200)
// 设置二维码背景色
Text('backgroundColor').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30)
QRCode(this.value).width(200).height(200).backgroundColor(Color.Orange)
}.width('100%').margin({ top: 5 }) }.width('100%').margin({ top: 5 })
} }
} }
``` ```
![zh-cn_image_0000001219662669](figures/zh-cn_image_0000001219662669.png) ![qrcode](figures/qrcode.png)
...@@ -21,7 +21,7 @@ ScrollBar(value: { scroller: Scroller, direction?: ScrollBarDirection, state?: B ...@@ -21,7 +21,7 @@ ScrollBar(value: { scroller: Scroller, direction?: ScrollBarDirection, state?: B
| 参数名 | 参数类型 | 必填 | 参数描述 | | 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| scroller | [Scroller](ts-container-scroll.md#scroller) | 是 | 可滚动组件的控制器。用于与可滚动组件进行绑定。 | | scroller | [Scroller](ts-container-scroll.md#scroller) | 是 | 可滚动组件的控制器。用于与可滚动组件进行绑定。 |
| direction | ScrollBarDirection | 否 | 滚动条的方向,控制可滚动组件对应方向的滚动。<br/>默认值:ScrollBarDirection.Vertical | | direction | [ScrollBarDirection](#scrollbardirection枚举说明) | 否 | 滚动条的方向,控制可滚动组件对应方向的滚动。<br/>默认值:ScrollBarDirection.Vertical |
| state | [BarState](ts-appendix-enums.md#barstate) | 否 | 滚动条状态。<br/>默认值:BarState.Auto | | state | [BarState](ts-appendix-enums.md#barstate) | 否 | 滚动条状态。<br/>默认值:BarState.Auto |
> **说明:** > **说明:**
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
## 接口 ## 接口
Select(options: Array\<SelectOption\>) Select(options: Array\<[SelectOption](#selectoption对象说明)\>)
**SelectOption对象说明:** ## SelectOption对象说明
| 参数名 | 参数类型 | 必填 | 参数描述 | | 参数名 | 参数类型 | 必填 | 参数描述 |
| ------ | ----------------------------------- | ---- | -------------- | | ------ | ----------------------------------- | ---- | -------------- |
...@@ -26,7 +26,7 @@ Select(options: Array\<SelectOption\>) ...@@ -26,7 +26,7 @@ Select(options: Array\<SelectOption\>)
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| ----------------------- | ------------------------------------- | --------------------------------------------- | | ----------------------- | ------------------------------------- | --------------------------------------------- |
| selected | number | 设置下拉菜单初始选项的索引,第一项的索引为0。 | | selected | number | 设置下拉菜单初始选项的索引,第一项的索引为0。 |
| value | string | 设置下拉按钮本身的文本显示。 | | value | string | 设置下拉按钮本身的文本内容。 |
| font | [Font](ts-types.md#font) | 设置下拉按钮本身的文本样式。 | | font | [Font](ts-types.md#font) | 设置下拉按钮本身的文本样式。 |
| fontColor | [ResourceColor](ts-types.md#resourcecolor) | 设置下拉按钮本身的文本颜色。 | | fontColor | [ResourceColor](ts-types.md#resourcecolor) | 设置下拉按钮本身的文本颜色。 |
| selectedOptionBgColor | [ResourceColor](ts-types.md#resourcecolor) | 设置下拉菜单选中项的背景色。 | | selectedOptionBgColor | [ResourceColor](ts-types.md#resourcecolor) | 设置下拉菜单选中项的背景色。 |
......
...@@ -30,7 +30,7 @@ Span(value: string | Resource) ...@@ -30,7 +30,7 @@ Span(value: string | Resource)
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| decoration | {<br/>type:&nbsp;[TextDecorationType](ts-appendix-enums.md#textdecorationtype),<br/>color?:&nbsp;[ResourceColor](ts-types.md#resourcecolor)<br/>} | 设置文本装饰线样式及其颜色。<br/>默认值:{<br/>type:&nbsp;TextDecorationType.None<br/>color:Color.Black<br/>} | | decoration | {<br/>type:&nbsp;[TextDecorationType](ts-appendix-enums.md#textdecorationtype),<br/>color?:&nbsp;[ResourceColor](ts-types.md#resourcecolor)<br/>} | 设置文本装饰线样式及其颜色。<br/>默认值:{<br/>type:&nbsp;TextDecorationType.None<br/>color:Color.Black<br/>} |
| letterSpacing | number \| string | 设置文本字符间距。 | | letterSpacing | number \| string | 设置文本字符间距。取值小于0,字符聚集重叠,取值大于0且随着数值变大,字符间距越来越大,稀疏分布。 |
| textCase | [TextCase](ts-appendix-enums.md#textcase) | 设置文本大小写。<br/>默认值:TextCase.Normal | | textCase | [TextCase](ts-appendix-enums.md#textcase) | 设置文本大小写。<br/>默认值:TextCase.Normal |
...@@ -58,29 +58,59 @@ struct SpanExample { ...@@ -58,29 +58,59 @@ struct SpanExample {
.decoration({ type: TextDecorationType.None, color: Color.Red }) .decoration({ type: TextDecorationType.None, color: Color.Red })
} }
// 文本横线添加
Text('Text Decoration').fontSize(9).fontColor(0xCCCCCC) Text('Text Decoration').fontSize(9).fontColor(0xCCCCCC)
Text() { Text() {
Span('I am Underline-span').decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(12) Span('I am Underline-span').decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(12)
} }
Text() { Text() {
Span('I am LineThrough-span').decoration({ type: TextDecorationType.LineThrough, color: Color.Red }).fontSize(12) Span('I am LineThrough-span')
.decoration({ type: TextDecorationType.LineThrough, color: Color.Red })
.fontSize(12)
} }
Text() { Text() {
Span('I am Overline-span').decoration({ type: TextDecorationType.Overline, color: Color.Red }).fontSize(12) Span('I am Overline-span').decoration({ type: TextDecorationType.Overline, color: Color.Red }).fontSize(12)
} }
// 文本字符间距
Text('LetterSpacing').fontSize(9).fontColor(0xCCCCCC)
Text() {
Span('span letter spacing')
.letterSpacing(0)
.fontSize(12)
}
Text() {
Span('span letter spacing')
.letterSpacing(-2)
.fontSize(12)
}
Text() {
Span('span letter spacing')
.letterSpacing(3)
.fontSize(12)
}
// 文本大小写展示设置
Text('Text Case').fontSize(9).fontColor(0xCCCCCC) Text('Text Case').fontSize(9).fontColor(0xCCCCCC)
Text() { Text() {
Span('I am Lower-span').textCase(TextCase.LowerCase).fontSize(12) Span('I am Lower-span').fontSize(12)
.decoration({ type: TextDecorationType.None, color: Color.Red }) .textCase(TextCase.LowerCase)
.decoration({ type: TextDecorationType.None })
} }
Text() { Text() {
Span('I am Upper-span').textCase(TextCase.UpperCase).fontSize(12) Span('I am Upper-span').fontSize(12)
.decoration({ type: TextDecorationType.None, color: Color.Red }) .textCase(TextCase.UpperCase)
.decoration({ type: TextDecorationType.None })
} }
}.width('100%').height(250).padding({ left: 35, right: 35, top: 35 }) }.width('100%').height(250).padding({ left: 35, right: 35, top: 35 })
} }
} }
``` ```
![zh-cn_image_0000001219982709](figures/zh-cn_image_0000001219982709.gif) ![span](figures/span.png)
...@@ -32,7 +32,7 @@ Text(content?: string | Resource) ...@@ -32,7 +32,7 @@ Text(content?: string | Resource)
| textOverflow | {overflow:&nbsp;[TextOverflow](ts-appendix-enums.md#textoverflow)} | 设置文本超长时的显示方式。<br/>默认值:{overflow:&nbsp;TextOverflow.Clip}<br/>**说明:**<br/>文本截断是按字截断。例如,英文以单词为最小单位进行截断,若需要以字母为单位进行截断,可在字母间添加零宽空格:\u200B。<br />需配合`maxLines`使用,单独设置不生效。 | | textOverflow | {overflow:&nbsp;[TextOverflow](ts-appendix-enums.md#textoverflow)} | 设置文本超长时的显示方式。<br/>默认值:{overflow:&nbsp;TextOverflow.Clip}<br/>**说明:**<br/>文本截断是按字截断。例如,英文以单词为最小单位进行截断,若需要以字母为单位进行截断,可在字母间添加零宽空格:\u200B。<br />需配合`maxLines`使用,单独设置不生效。 |
| maxLines | number | 设置文本的最大行数。<br />默认值:Infinity<br/>**说明:**<br />默认情况下,文本是自动折行的,如果指定此参数,则文本最多不会超过指定的行。如果有多余的文本,可以通过 `textOverflow`来指定截断方式。 | | maxLines | number | 设置文本的最大行数。<br />默认值:Infinity<br/>**说明:**<br />默认情况下,文本是自动折行的,如果指定此参数,则文本最多不会超过指定的行。如果有多余的文本,可以通过 `textOverflow`来指定截断方式。 |
| lineHeight | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 设置文本的文本行高,设置值不大于0时,不限制文本行高,自适应字体大小,Length为number类型时单位为fp。 | | lineHeight | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 设置文本的文本行高,设置值不大于0时,不限制文本行高,自适应字体大小,Length为number类型时单位为fp。 |
| decoration | {<br/>type:&nbsp;TextDecorationType,<br/>color?:&nbsp;[ResourceColor](ts-types.md#resourcecolor)<br/>} | 设置文本装饰线样式及其颜色。<br />默认值:{<br/>type:&nbsp;TextDecorationType.None,<br/>color:Color.Black<br/>} | | decoration | {<br/>type:&nbsp;[TextDecorationType](ts-appendix-enums.md#textdecorationtype),<br/>color?:&nbsp;[ResourceColor](ts-types.md#resourcecolor)<br/>} | 设置文本装饰线样式及其颜色。<br />默认值:{<br/>type:&nbsp;TextDecorationType.None,<br/>color:Color.Black<br/>} |
| baselineOffset | number&nbsp;\|&nbsp;string | 设置文本基线的偏移量。 | | baselineOffset | number&nbsp;\|&nbsp;string | 设置文本基线的偏移量。 |
| letterSpacing | number&nbsp;\|&nbsp;string | 设置文本字符间距。 | | letterSpacing | number&nbsp;\|&nbsp;string | 设置文本字符间距。 |
| minFontSize | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 设置文本最小显示字号。 | | minFontSize | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 设置文本最小显示字号。 |
......
...@@ -21,30 +21,15 @@ TextClock(options?: { timeZoneOffset?: number, controller?: TextClockController ...@@ -21,30 +21,15 @@ TextClock(options?: { timeZoneOffset?: number, controller?: TextClockController
| timeZoneOffset | number | 否 | 设置时区偏移量。<br>取值范围为[-14, 12],表示东十二区到西十二区,其中负值表示东时区,正值表示西时区,比如东八区为-8。<br>对横跨国际日界线的国家或地区,用-13(UTC+13)和-14(UTC+14)来保证整个国家或者区域处在相同的时间,当设置的值不在取值范围内时,将使用当前系统的时区偏移量。<br/>默认值:当前系统的时区偏移量 | | timeZoneOffset | number | 否 | 设置时区偏移量。<br>取值范围为[-14, 12],表示东十二区到西十二区,其中负值表示东时区,正值表示西时区,比如东八区为-8。<br>对横跨国际日界线的国家或地区,用-13(UTC+13)和-14(UTC+14)来保证整个国家或者区域处在相同的时间,当设置的值不在取值范围内时,将使用当前系统的时区偏移量。<br/>默认值:当前系统的时区偏移量 |
| controller | [TextClockController](#textclockcontroller) | 否 | 绑定一个控制器,用来控制文本时钟的状态。| | controller | [TextClockController](#textclockcontroller) | 否 | 绑定一个控制器,用来控制文本时钟的状态。|
## 属性
除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
| 名称 | 参数类型 | 描述 |
| ------ | --------------- | ------------------------------------------------------------ |
| format | string | 设置显示时间格式。<br/>日期间隔符固定为"/",时间间隔符为":"。<br/>如yyyyMMdd,yyyy-MM-dd显示为yyyy/MM/dd,<br/>hhmmss显示为hh:mm:ss。 <br/>时间格式只用写一位即可,如"hhmmss"等同于"hms"。<br/>支持的时间格式化字符串:<br/>- YYYY/yyyy:完整年份。<br/>- YY/yy:年份后两位。<br/>- M:月份(若想使用01月则使用MM)。<br/>- d:日期(若想使用01日则使用dd)。<br/>- D:年中日(一年中的第几天)。<br/>- H:24小时制。<br/>- h:12小时制。<br/>- m:分钟。<br/>- s:秒。<br/>- SSS:毫秒。<br/>默认值: 'hms'|
## 事件
除支持[通用事件](ts-universal-events-click.md)外,还支持以下事件:
| 名称 | 功能描述 |
| -------------------------------------------- | ------------------------------------------------------------ |
| onDateChange(event: (value: number) => void) | 提供时间变化回调,该事件最小回调间隔为秒。<br /> - value: Unix Time Stamp,即自1970年1月1日(UTC)起经过的毫秒数。 |
## TextClockController ## TextClockController
TextClock容器组件的控制器,可以将此对象绑定到TextClock组件,再通过它控制文本时钟的启动与停止。一个TextClock组件仅支持绑定一个控制器。 TextClock容器组件的控制器,可以将该控制器绑定到TextClock组件,通过它控制文本时钟的启动与停止。一个TextClock组件仅支持绑定一个控制器。
### 导入对象 ### 导入对象
```ts ```ts
controller: TextClockController = new TextClockController() controller: TextClockController = new TextClockController();
``` ```
### start ### start
...@@ -60,15 +45,32 @@ stop() ...@@ -60,15 +45,32 @@ stop()
停止文本时钟。 停止文本时钟。
## 属性
除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
| 名称 | 参数类型 | 描述 |
| ------ | --------------- | ------------------------------------------------------------ |
| format | string | 设置显示时间格式。<br/>日期间隔符固定为"/",时间间隔符为":"。<br/>如yyyyMMdd,yyyy-MM-dd显示为yyyy/MM/dd,<br/>hhmmss显示为hh:mm:ss。 <br/>时间格式只用写一位即可,如"hhmmss"等同于"hms"。<br/>支持的时间格式化字符串:<br/>- YYYY/yyyy:完整年份。<br/>- YY/yy:年份后两位。<br/>- M:月份(若想使用01月则使用MM)。<br/>- d:日期(若想使用01日则使用dd)。<br/>- D:年中日(一年中的第几天)。<br/>- H:24小时制。<br/>- h:12小时制。<br/>- m:分钟。<br/>- s:秒。<br/>- SSS:毫秒。<br/>默认值: 'hms'|
## 事件
除支持[通用事件](ts-universal-events-click.md)外,还支持以下事件:
| 名称 | 功能描述 |
| -------------------------------------------- | ------------------------------------------------------------ |
| onDateChange(event: (value: number) => void) | 提供时间变化回调,该事件最小回调间隔为秒。<br /> value: Unix Time Stamp,即自1970年1月1日(UTC)起经过的毫秒数。 |
## 示例 ## 示例
```ts ```ts
@Entry @Entry
@Component @Component
struct Second { struct Second {
@State accumulateTime: number = 0 @State accumulateTime: number = 0;
controller: TextClockController = new TextClockController() // 导入对象
controller: TextClockController = new TextClockController();
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Current milliseconds is ' + this.accumulateTime) Text('Current milliseconds is ' + this.accumulateTime)
...@@ -77,18 +79,20 @@ struct Second { ...@@ -77,18 +79,20 @@ struct Second {
TextClock({ timeZoneOffset: -8, controller: this.controller }) TextClock({ timeZoneOffset: -8, controller: this.controller })
.format('hms') .format('hms')
.onDateChange((value: number) => { .onDateChange((value: number) => {
this.accumulateTime = value this.accumulateTime = value;
}) })
.margin(20) .margin(20)
.fontSize(30) .fontSize(30)
Button("start TextClock") Button("start TextClock")
.margin({ bottom: 10 }) .margin({ bottom: 10 })
.onClick(() => { .onClick(() => {
this.controller.start() // 启动文本时钟
this.controller.start();
}) })
Button("stop TextClock") Button("stop TextClock")
.onClick(() => { .onClick(() => {
this.controller.stop() // 停止文本时钟
this.controller.stop();
}) })
} }
.width('100%') .width('100%')
...@@ -96,5 +100,5 @@ struct Second { ...@@ -96,5 +100,5 @@ struct Second {
} }
} }
``` ```
![](figures/text_clock.png) ![text_clock](figures/text_clock.gif)
...@@ -22,9 +22,9 @@ TextPicker(options?: {range: string[]|Resource, selected?: number, value?: strin ...@@ -22,9 +22,9 @@ TextPicker(options?: {range: string[]|Resource, selected?: number, value?: strin
| 参数名 | 参数类型 | 必填 | 参数描述 | | 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| range | string[]&nbsp;\|&nbsp;[Resource](ts-types.md#resource类型) | 是 | 选择器的数据选择范围。 | | range | string[]&nbsp;\|&nbsp;[Resource](ts-types.md#resource类型) | 是 | 选择器的数据选择列表。 |
| selected | number | 否 | 选中项在数组中的index值。<br/>默认值:0 | | selected | number | 否 | 设置默认选中项在数组中的index值。<br/>默认值:0 |
| value | string | 否 | 选中项的值,优先级低于selected。<br/>默认值:第一个元素值 | | value | string | 否 | 设置默认选中项的值,优先级低于selected。<br/>默认值:第一个元素值 |
## 属性 ## 属性
......
...@@ -6,11 +6,6 @@ ...@@ -6,11 +6,6 @@
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 子组件 ## 子组件
支持单个子组件。 支持单个子组件。
...@@ -42,15 +37,6 @@ ...@@ -42,15 +37,6 @@
| position | [BadgePosition](#badgeposition枚举说明) | 否 | BadgePosition.RightTop | 设置提示点显示位置。 | | position | [BadgePosition](#badgeposition枚举说明) | 否 | BadgePosition.RightTop | 设置提示点显示位置。 |
| style | [BadgeStyle](#badgestyle对象说明) | 是 | - | Badge组件可设置样式,支持设置文本颜色、尺寸、圆点颜色和尺寸。 | | style | [BadgeStyle](#badgestyle对象说明) | 是 | - | Badge组件可设置样式,支持设置文本颜色、尺寸、圆点颜色和尺寸。 |
## BadgeStyle对象说明
| 名称 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- |
| color | [ResourceColor](ts-types.md) | 否 | Color.White | 文本颜色。 |
| fontSize | number&nbsp;\|&nbsp;string | 否 | 10 | 文本大小。 |
| badgeSize | number&nbsp;\|&nbsp;string | 是 | - | badge的大小。 |
| badgeColor | [ResourceColor](ts-types.md) | 否 | Color.Red | badge的颜色。 |
## BadgePosition枚举说明 ## BadgePosition枚举说明
| 名称 | 描述 | | 名称 | 描述 |
...@@ -59,6 +45,13 @@ ...@@ -59,6 +45,13 @@
| Right | 圆点显示在右侧纵向居中。 | | Right | 圆点显示在右侧纵向居中。 |
| Left | 圆点显示在左侧纵向居中。 | | Left | 圆点显示在左侧纵向居中。 |
## BadgeStyle对象说明
| 名称 | 类型 | 必填 | 默认值 | 描述 |
| -------- | -------- | -------- | -------- | -------- |
| color | [ResourceColor](ts-types.md#resourcecolor) | 否 | Color.White | 文本颜色。 |
| fontSize | number&nbsp;\|&nbsp;string | 否 | 10 | 文本大小。 |
| badgeSize | number&nbsp;\|&nbsp;string | 是 | - | badge的大小。 |
| badgeColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | Color.Red | badge的颜色。 |
## 示例 ## 示例
...@@ -67,44 +60,92 @@ ...@@ -67,44 +60,92 @@
@Entry @Entry
@Component @Component
struct BadgeExample { struct BadgeExample {
@State counts: number = 1 @State counts: number = 1;
@State message: string = 'new' @State message: string = 'new';
build() { build() {
Flex({ justifyContent: FlexAlign.SpaceAround }) { Column() {
Badge({ Text('numberBadge').width('80%')
count: this.counts, Row({ space: 10 }) {
maxCount: 99, // 数字上标,maxCount默认99,超过99展示99+
style: { color: 0xFFFFFF, fontSize: 16, badgeSize: 20, badgeColor: Color.Red } Badge({
}) { count: this.counts,
Button('message') maxCount: 99,
.onClick(() => { position: BadgePosition.RightTop,
this.counts++ style: { color: 0xFFFFFF, fontSize: 16, badgeSize: 20, badgeColor: Color.Red }
}) }) {
.width(100).height(50).backgroundColor(0x317aff) Button('message')
}.width(100).height(50) .onClick(() => {
this.counts++;
Badge({ })
value: this.message, .width(100).height(50).backgroundColor(0x317aff)
style: { color: 0xFFFFFF, fontSize: 9, badgeSize: 20, badgeColor: Color.Blue } }.width(100).height(50)
}) {
Text('message') // 数字上标
.width(80).height(50).fontSize(16).lineHeight(37) Badge({
.borderRadius(10).textAlign(TextAlign.Center).backgroundColor(0xF3F4ED) count: this.counts,
}.width(80).height(50) maxCount: 99,
position: BadgePosition.Left,
Badge({ style: { color: 0xFFFFFF, fontSize: 16, badgeSize: 20, badgeColor: Color.Red }
value: ' ', }) {
position: BadgePosition.Right, Button('message')
style: { badgeSize: 6, badgeColor: Color.Red } .onClick(() => {
}) { this.counts++;
Text('message') })
.width(90).height(50).fontSize(16).lineHeight(37) .width(100).height(50).backgroundColor(0x317aff)
.borderRadius(10).textAlign(TextAlign.Center).backgroundColor(0xF3F4ED) }.width(100).height(50)
}.width(90).height(50)
}.width('100%').margin({ top: 5 })
// 数字上标
Badge({
count: this.counts,
maxCount: 99,
position: BadgePosition.Right,
style: { color: 0xFFFFFF, fontSize: 16, badgeSize: 20, badgeColor: Color.Red }
}) {
Button('message')
.onClick(() => {
this.counts++;
})
.width(100).height(50).backgroundColor(0x317aff)
}.width(100).height(50)
}.margin(10)
Text('stringBadge').width('80%')
Row({ space: 30 }) {
Badge({
value: this.message,
style: { color: 0xFFFFFF, fontSize: 9, badgeSize: 20, badgeColor: Color.Blue }
}) {
Text('message')
.width(80)
.height(50)
.fontSize(16)
.lineHeight(37)
.borderRadius(10)
.textAlign(TextAlign.Center)
.backgroundColor(0xF3F4ED)
}.width(80).height(50)
// value为空,设置圆点标记
Badge({
value: '',
position: BadgePosition.Right,
style: { badgeSize: 6, badgeColor: Color.Red }
}) {
Text('message')
.width(90)
.height(50)
.fontSize(16)
.lineHeight(37)
.borderRadius(10)
.textAlign(TextAlign.Center)
.backgroundColor(0xF3F4ED)
}.width(90).height(50)
}.margin(10)
}
} }
} }
``` ```
![zh-cn_image_0000001219864147](figures/zh-cn_image_0000001219864147.gif) ![badge](figures/badge.png)
...@@ -20,7 +20,7 @@ Column(value?:&nbsp;{space?: string&nbsp;|&nbsp;number}) ...@@ -20,7 +20,7 @@ Column(value?:&nbsp;{space?: string&nbsp;|&nbsp;number})
| 参数名 | 参数类型 | 必填 | 参数描述 | | 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| space | string&nbsp;\|&nbsp;number | 否 | 纵向布局元素间距。<br/>默认值:0 | | space | string&nbsp;\|&nbsp;number | 否 | 纵向布局元素垂直方向间距。<br/>默认值:0 |
## 属性 ## 属性
...@@ -40,38 +40,47 @@ Column(value?:&nbsp;{space?: string&nbsp;|&nbsp;number}) ...@@ -40,38 +40,47 @@ Column(value?:&nbsp;{space?: string&nbsp;|&nbsp;number})
struct ColumnExample { struct ColumnExample {
build() { build() {
Column() { Column() {
Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%') // 设置子元素垂直方向间距为5
Column({ space: 5 }) { Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column().width('100%').height(30).backgroundColor(0xAFEEEE) Column({ space: 5 }) {
Column().width('100%').height(30).backgroundColor(0x00FFFF) Column().width('100%').height(30).backgroundColor(0xAFEEEE)
}.width('90%').height(100).border({ width: 1 }) Column().width('100%').height(30).backgroundColor(0x00FFFF)
}.width('90%').height(100).border({ width: 1 })
Text('alignItems(Start)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column() { // 设置子元素水平方向对齐方式
Column().width('50%').height(30).backgroundColor(0xAFEEEE) Text('alignItems(Start)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column().width('50%').height(30).backgroundColor(0x00FFFF) Column() {
}.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 }) Column().width('50%').height(30).backgroundColor(0xAFEEEE)
Column().width('50%').height(30).backgroundColor(0x00FFFF)
Text('alignItems(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') }.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 })
Column() {
Column().width('50%').height(30).backgroundColor(0xAFEEEE) Text('alignItems(End)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column().width('50%').height(30).backgroundColor(0x00FFFF) Column() {
}.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 }) Column().width('50%').height(30).backgroundColor(0xAFEEEE)
Column().width('50%').height(30).backgroundColor(0x00FFFF)
Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') }.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 })
Column() {
Column().width('30%').height(30).backgroundColor(0xAFEEEE) Text('alignItems(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column().width('30%').height(30).backgroundColor(0x00FFFF) Column() {
}.height('15%').border({ width: 1 }).justifyContent(FlexAlign.Center) Column().width('50%').height(30).backgroundColor(0xAFEEEE)
Column().width('50%').height(30).backgroundColor(0x00FFFF)
Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') }.alignItems(HorizontalAlign.Center).width('90%').border({ width: 1 })
Column() {
Column().width('30%').height(30).backgroundColor(0xAFEEEE) // 设置子元素垂直方向的对齐方式
Column().width('30%').height(30).backgroundColor(0x00FFFF) Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%')
}.height('15%').border({ width: 1 }).justifyContent(FlexAlign.End) Column() {
Column().width('90%').height(30).backgroundColor(0xAFEEEE)
Column().width('90%').height(30).backgroundColor(0x00FFFF)
}.height(100).border({ width: 1 }).justifyContent(FlexAlign.Center)
Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column() {
Column().width('90%').height(30).backgroundColor(0xAFEEEE)
Column().width('90%').height(30).backgroundColor(0x00FFFF)
}.height(100).border({ width: 1 }).justifyContent(FlexAlign.End)
}.width('100%').padding({ top: 5 }) }.width('100%').padding({ top: 5 })
} }
} }
``` ```
![zh-cn_image_0000001219982721](figures/Column.png) ![column](figures/column.png)
# ColumnSplit # ColumnSplit
> **说明:**
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
将子组件纵向布局,并在每个子组件之间插入一根横向的分割线。 将子组件纵向布局,并在每个子组件之间插入一根横向的分割线。
> **说明:**
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 子组件 ## 子组件
...@@ -30,7 +25,8 @@ ColumnSplit() ...@@ -30,7 +25,8 @@ ColumnSplit()
> **说明:** > **说明:**
> 与RowSplit相同,ColumnSplit的分割线最小能拖动到刚好包含子组件。 > 与RowSplit相同,ColumnSplit的分割线最小能拖动到刚好包含子组件。
>
> 在真机中查看拖动效果,预览器中不支持拖动。
## 示例 ## 示例
...@@ -49,7 +45,7 @@ struct ColumnSplitExample { ...@@ -49,7 +45,7 @@ struct ColumnSplitExample {
Text('4').width('100%').height(50).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) Text('4').width('100%').height(50).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
Text('5').width('100%').height(50).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) Text('5').width('100%').height(50).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
} }
.resizeable(true) .resizeable(true) // 可拖动
.width('90%').height('60%') .width('90%').height('60%')
}.width('100%') }.width('100%')
} }
......
# Counter # Counter
计数器组件,提供相应的增加或者减少的计数操作。
> **说明:** > **说明:**
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
计数器组件,提供相应的增加或者减少的计数操作。
## 权限列表
## 子组件 ## 子组件
......
...@@ -20,8 +20,8 @@ Navigator(value?: {target: string, type?: NavigationType}) ...@@ -20,8 +20,8 @@ Navigator(value?: {target: string, type?: NavigationType})
| 参数名 | 参数类型 | 必填 | 参数描述 | | 参数名 | 参数类型 | 必填 | 参数描述 |
| ------ | -------------- | ---- | ---------------------------------------------- | | ------ | -------------- | ---- | ---------------------------------------------- |
| target | string | 是 | 指定跳转目标页面的路径。 | | target | string | 是 | 指定跳转目标页面的路径。 |
| type | NavigationType | 否 | 指定路由方式。<br/>默认值:NavigationType.Push | | type | [NavigationType](#navigationtype枚举说明) | 否 | 指定路由方式。<br/>默认值:NavigationType.Push |
## NavigationType枚举说明 ## NavigationType枚举说明
...@@ -37,9 +37,9 @@ Navigator(value?: {target: string, type?: NavigationType}) ...@@ -37,9 +37,9 @@ Navigator(value?: {target: string, type?: NavigationType})
| 名称 | 参数 | 描述 | | 名称 | 参数 | 描述 |
| ------ | ------- | ------------------------------------------------------------ | | ------ | ------- | ------------------------------------------------------------ |
| active | boolean | 当前路由组件是否处于激活状态,处于激活状态时,会生效相应的路由操作。 | | active | boolean | 当前路由组件是否处于激活状态,处于激活状态时,会生效相应的路由操作。 |
| params | object | 跳转时要同时传递到目标页面的数据,可在目标页面使用router.getParams()获得。 | | params | object | 跳转时要同时传递到目标页面的数据,可在目标页面使用[router.getParams()](../apis/js-api-router.md#routergetparams)获得。 |
| target | string | 设置跳转目标页面的路径。 | | target | string | 设置跳转目标页面的路径。 目标页面需加入main_pages.json文件中。 |
| type | NavigationType | 设置路由方式。<br/>默认值:NavigationType.Push | | type | [NavigationType](#navigationtype枚举说明) | 设置路由方式。<br/>默认值:NavigationType.Push |
## 示例 ## 示例
...@@ -57,7 +57,7 @@ struct NavigatorExample { ...@@ -57,7 +57,7 @@ struct NavigatorExample {
Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) { Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) {
Text('Go to ' + this.Text['name'] + ' page') Text('Go to ' + this.Text['name'] + ' page')
.width('100%').textAlign(TextAlign.Center) .width('100%').textAlign(TextAlign.Center)
}.params({ text: this.Text }) }.params({ text: this.Text }) // 传参数到Detail页面
Navigator() { Navigator() {
Text('Back to previous page').width('100%').textAlign(TextAlign.Center) Text('Back to previous page').width('100%').textAlign(TextAlign.Center)
...@@ -72,11 +72,12 @@ struct NavigatorExample { ...@@ -72,11 +72,12 @@ struct NavigatorExample {
```ts ```ts
// Detail.ets // Detail.ets
import router from '@system.router' import router from '@ohos.router'
@Entry @Entry
@Component @Component
struct DetailExample { struct DetailExample {
// 接收Navigator.ets的传参
@State text: any = router.getParams().text @State text: any = router.getParams().text
build() { build() {
......
...@@ -27,8 +27,8 @@ Panel(show: boolean) ...@@ -27,8 +27,8 @@ Panel(show: boolean)
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| type | PanelType | 设置可滑动面板的类型。<br/>默认值:PanelType.Foldable | | type | [PanelType](#paneltype枚举说明) | 设置可滑动面板的类型。<br/>默认值:PanelType.Foldable |
| mode | PanelMode | 设置可滑动面板的初始状态。 | | mode | [PanelMode](#panelmode枚举说明) | 设置可滑动面板的初始状态。 |
| dragBar | boolean | 设置是否存在dragbar,true表示存在,false表示不存在。<br/>默认值:true | | dragBar | boolean | 设置是否存在dragbar,true表示存在,false表示不存在。<br/>默认值:true |
| fullHeight | string&nbsp;\|&nbsp;number | 指定PanelMode.Full状态下的高度。 | | fullHeight | string&nbsp;\|&nbsp;number | 指定PanelMode.Full状态下的高度。 |
| halfHeight | string&nbsp;\|&nbsp;number | 指定PanelMode.Half状态下的高度,默认为屏幕尺寸的一半。 | | halfHeight | string&nbsp;\|&nbsp;number | 指定PanelMode.Half状态下的高度,默认为屏幕尺寸的一半。 |
......
...@@ -29,7 +29,7 @@ Refresh\(value: \{ refreshing: boolean, offset?: number&nbsp;|&nbsp;string , fr ...@@ -29,7 +29,7 @@ Refresh\(value: \{ refreshing: boolean, offset?: number&nbsp;|&nbsp;string , fr
| 名称 | 描述 | | 名称 | 描述 |
| -------- | -------- | | -------- | -------- |
| onStateChange(callback: (state: RefreshStatus) => void)| 当前刷新状态变更时,触发回调。<br/>-&nbsp;state:刷新状态。 | | onStateChange(callback: (state: [RefreshStatus](#refreshstatus枚举说明)) => void)| 当前刷新状态变更时,触发回调。<br/>-&nbsp;state:刷新状态。 |
| onRefreshing(callback: () => void)| 进入刷新状态时触发回调。 | | onRefreshing(callback: () => void)| 进入刷新状态时触发回调。 |
## RefreshStatus枚举说明 ## RefreshStatus枚举说明
......
...@@ -10,22 +10,18 @@ ...@@ -10,22 +10,18 @@
## 规则说明 ## 规则说明
* 容器内子组件区分水平方向,垂直方向: * 容器内子组件区分水平方向,垂直方向:
* 水平方向为left, middle, right,对应容器的HorizontalAlign.Start, HorizontalAlign.Center, HorizontalAlign.End * 水平方向为left, middle, right,对应容器的HorizontalAlign.Start, HorizontalAlign.Center, HorizontalAlign.End
* 垂直方向为top, center, bottom,对应容器的VerticalAlign.Top, VerticalAlign.Center, VerticalAlign.Bottom * 垂直方向为top, center, bottom,对应容器的VerticalAlign.Top, VerticalAlign.Center, VerticalAlign.Bottom
* 子组件可以将容器或者其他子组件设为锚点: * 子组件可以将容器或者其他子组件设为锚点:
* 参与相对布局的容器内组件必须设置id,容器id固定为__container__ * 参与相对布局的容器内组件必须设置id,容器RelativeContainer的id固定为'__container__'。
* 无id的子组件位置设置默认为容器左上方 * 无id的子组件位置设置默认为容器左上方
* 此子组件某一方向上的三个位置可以将容器或其他子组件的同方向三个位置为锚点,同方向上两个以上位置设置锚点以后会跳过第三个 * 此子组件某一方向上的三个位置可以将容器或其他子组件的同方向三个位置为锚点,同方向上两个以上位置设置锚点以后会跳过第三个
* 同方向上两个以上位置设置锚点时此子组件额外设置width,height不生效 * 同方向上两个以上位置设置锚点时此子组件额外设置width,height不生效
* 对齐后需要额外偏移可设置offset * 对齐后需要额外偏移可设置offset
* 特殊情况 * 特殊情况
* 互相依赖,环形依赖时容器内子组件全部不绘制 * 互相依赖,环形依赖时容器内子组件全部不绘制。
* 同方向上两个以上位置设置锚点但锚点位置逆序时此子组件大小为0,即不绘制 * 同方向上两个以上位置设置锚点但锚点位置逆序时此子组件大小为0,即不绘制。
## 权限列表
## 子组件 ## 子组件
...@@ -42,49 +38,68 @@ RelativeContainer() ...@@ -42,49 +38,68 @@ RelativeContainer()
@Entry @Entry
@Component @Component
struct Index { struct Index {
build() { build() {
Row() { Row() {
Button("Extra button").width(100).height(50) Button("Extra button").width(100).height(50)
RelativeContainer() {
Button("Button 1").width(120).height(30) // 外层容器的id默认为为'__container__'
.alignRules({ RelativeContainer() {
middle: { anchor: "__container__", align: HorizontalAlign.Center }, Button("Button 1")
}) .width(120)
.id("bt1").borderWidth(1).borderColor(Color.Black) .height(30)
Text("This is text 2").fontSize(20).padding(10) .alignRules({
.alignRules({ middle: { anchor: "__container__", align: HorizontalAlign.Center }, // 水平方向上,组件中部与容器中间对齐,即组件在容器中水平居中
bottom: { anchor: "__container__", align: VerticalAlign.Bottom }, })
top: { anchor: "bt1", align: VerticalAlign.Bottom }, .id("bt1") // id设置为bt1
right:{ anchor: "bt1", align: HorizontalAlign.Center } .borderWidth(1)
}).id("tx2").borderWidth(1).borderColor(Color.Black).height(30) .borderColor(Color.Black)
LoadingProgress().color(Color.Blue) Text("This is text 2")
.alignRules({ .fontSize(20)
left: { anchor: "bt1", align: HorizontalAlign.End }, .padding(10)
top: { anchor: "tx2", align: VerticalAlign.Center }, .borderWidth(1)
bottom: { anchor: "__container__", align: VerticalAlign.Bottom } .borderColor(Color.Black)
}).id("lp3").borderWidth(1).borderColor(Color.Black) .height(30)
.height(30).width(30) .id("tx2") // id设置为tx2
.alignRules({
Gauge({ value: 50, min: 0, max: 100 }) bottom: { anchor: "__container__", align: VerticalAlign.Bottom }, // 组件下边与容器下边对齐
.startAngle(210).endAngle(150) top: { anchor: "bt1", align: VerticalAlign.Bottom }, // 组件上边与button1底部对齐
.colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1], [0xD94838, 1]]) right: { anchor: "bt1", align: HorizontalAlign.Center } // 组件右侧与button1中间点对齐
.strokeWidth(20) })
.width(50).height(50)
.alignRules({ LoadingProgress()
left: { anchor: "tx2", align: HorizontalAlign.End }, .color(Color.Blue)
right:{ anchor: "__container__", align: HorizontalAlign.End }, .borderWidth(1)
top: { anchor: "__container__", align: VerticalAlign.Top }, .borderColor(Color.Black)
bottom: { anchor: "lp3", align: VerticalAlign.Top } .height(30)
}).id("g4").borderWidth(1).borderColor(Color.Black) .width(30)
.id("lp3") // id设置为lp3
} .alignRules({
.width(200).height(200) left: { anchor: "bt1", align: HorizontalAlign.End }, // 组件左边对齐容器bt1的右边
.backgroundColor(Color.Orange) top: { anchor: "tx2", align: VerticalAlign.Center }, // 组件上边对齐容器tx2的中间
bottom: { anchor: "__container__", align: VerticalAlign.Bottom } // 组件下边对齐最外层容器的底边
} })
.height('100%')
Gauge({ value: 50, min: 0, max: 100 })
.startAngle(210)
.endAngle(150)
.colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1], [0xD94838, 1]])
.strokeWidth(20)
.width(50)
.height(50)
.alignRules({
left: { anchor: "tx2", align: HorizontalAlign.End }, // 组件左边对齐容器tx2的右边
right: { anchor: "__container__", align: HorizontalAlign.End }, // 组件右边对齐最外层容器的右边
top: { anchor: "__container__", align: VerticalAlign.Top }, // 组件上边对齐最外层容器的上边
bottom: { anchor: "lp3", align: VerticalAlign.Top } // 组件下边对齐容器lp3的上边
})
.id("g4")
.borderWidth(1)
.borderColor(Color.Black)
}
.width(200).height(200)
.backgroundColor(Color.Orange)
}.height('100%')
} }
} }
``` ```
......
...@@ -40,38 +40,41 @@ Row(value?:{space?: number&nbsp;|&nbsp;string }) ...@@ -40,38 +40,41 @@ Row(value?:{space?: number&nbsp;|&nbsp;string })
struct RowExample { struct RowExample {
build() { build() {
Column({ space: 5 }) { Column({ space: 5 }) {
// 设置子组件水平方向的间距为5
Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row({ space: 5 }) { Row({ space: 5 }) {
Row().width('30%').height(50).backgroundColor(0xAFEEEE) Row().width('30%').height(50).backgroundColor(0xAFEEEE)
Row().width('30%').height(50).backgroundColor(0x00FFFF) Row().width('30%').height(50).backgroundColor(0x00FFFF)
}.width('90%').height(107).border({ width: 1 }) }.width('90%').height(107).border({ width: 1 })
Text('alignItems(Top)').fontSize(9).fontColor(0xCCCCCC).width('90%') // 设置子元素垂直方向对齐方式
Row() { Text('alignItems(Bottom)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row().width('30%').height(50).backgroundColor(0xAFEEEE) Row() {
Row().width('30%').height(50).backgroundColor(0x00FFFF) Row().width('30%').height(50).backgroundColor(0xAFEEEE)
}.alignItems(VerticalAlign.Top).height('15%').border({ width: 1 }) Row().width('30%').height(50).backgroundColor(0x00FFFF)
}.width('90%').alignItems(VerticalAlign.Bottom).height('15%').border({ width: 1 })
Text('alignItems(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row() { Text('alignItems(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row().width('30%').height(50).backgroundColor(0xAFEEEE) Row() {
Row().width('30%').height(50).backgroundColor(0x00FFFF) Row().width('30%').height(50).backgroundColor(0xAFEEEE)
}.alignItems(VerticalAlign.Center).height('15%').border({ width: 1 }) Row().width('30%').height(50).backgroundColor(0x00FFFF)
}.width('90%').alignItems(VerticalAlign.Center).height('15%').border({ width: 1 })
Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row() { // 设置子元素水平方向对齐方式
Row().width('30%').height(50).backgroundColor(0xAFEEEE) Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row().width('30%').height(50).backgroundColor(0x00FFFF) Row() {
}.width('90%').border({ width: 1 }).justifyContent(FlexAlign.End) Row().width('30%').height(50).backgroundColor(0xAFEEEE)
Row().width('30%').height(50).backgroundColor(0x00FFFF)
Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') }.width('90%').border({ width: 1 }).justifyContent(FlexAlign.End)
Row() {
Row().width('30%').height(50).backgroundColor(0xAFEEEE) Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row().width('30%').height(50).backgroundColor(0x00FFFF) Row() {
}.width('90%').border({ width: 1 }).justifyContent(FlexAlign.Center) Row().width('30%').height(50).backgroundColor(0xAFEEEE)
Row().width('30%').height(50).backgroundColor(0x00FFFF)
}.width('90%').border({ width: 1 }).justifyContent(FlexAlign.Center)
}.width('100%') }.width('100%')
} }
} }
``` ```
![zh-cn_image_0000001174422908](figures/Row.png) ![row](figures/row.png)
...@@ -7,10 +7,6 @@ ...@@ -7,10 +7,6 @@
将子组件横向布局,并在每个子组件之间插入一根纵向的分割线。 将子组件横向布局,并在每个子组件之间插入一根纵向的分割线。
## 权限列表
## 子组件 ## 子组件
...@@ -30,6 +26,8 @@ RowSplit() ...@@ -30,6 +26,8 @@ RowSplit()
> **说明:** > **说明:**
> RowSplit的分割线最小能拖动到刚好包含子组件。 > RowSplit的分割线最小能拖动到刚好包含子组件。
>
> 在真机中查看拖动效果,预览器中不支持拖动。
## 示例 ## 示例
......
...@@ -24,11 +24,11 @@ Scroll(scroller?: Scroller) ...@@ -24,11 +24,11 @@ Scroll(scroller?: Scroller)
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| -------------- | ---------------------------------------- | --------- | | -------------- | ---------------------------------------- | --------- |
| scrollable | ScrollDirection | 设置滚动方向。<br/>默认值:ScrollDirection.Vertical | | scrollable | [ScrollDirection](#scrolldirection枚举说明) | 设置滚动方向。<br/>默认值:ScrollDirection.Vertical |
| scrollBar | [BarState](ts-appendix-enums.md#barstate) | 设置滚动条状态。<br/>默认值:BarState.Off | | scrollBar | [BarState](ts-appendix-enums.md#barstate) | 设置滚动条状态。<br/>默认值:BarState.Off |
| scrollBarColor | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;Color | 设置滚动条的颜色。 | | scrollBarColor | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;[Color](ts-appendix-enums.md#color) | 设置滚动条的颜色。 |
| scrollBarWidth | string&nbsp;\|&nbsp;number | 设置滚动条的宽度。 | | scrollBarWidth | string&nbsp;\|&nbsp;number | 设置滚动条的宽度。 |
| edgeEffect | [EdgeEffect](ts-appendix-enums.md#edgeeffect) | 设置滑动效果,目前支持的滑动效果参见EdgeEffect的枚举说明。<br/>默认值:EdgeEffect.Spring | | edgeEffect | [EdgeEffect](ts-appendix-enums.md#edgeeffect) | 设置滑动效果,目前支持的滑动效果参见EdgeEffect的枚举说明。<br/>默认值:EdgeEffect.None |
## ScrollDirection枚举说明 ## ScrollDirection枚举说明
| 名称 | 描述 | | 名称 | 描述 |
...@@ -93,8 +93,6 @@ scrollEdge(value: Edge): void ...@@ -93,8 +93,6 @@ scrollEdge(value: Edge): void
| value | [Edge](ts-appendix-enums.md#edge) | 是 | 滚动到的边缘位置。 | | value | [Edge](ts-appendix-enums.md#edge) | 是 | 滚动到的边缘位置。 |
### scrollPage ### scrollPage
scrollPage(value: { next: boolean, direction?: Axis }): void scrollPage(value: { next: boolean, direction?: Axis }): void
...@@ -163,14 +161,15 @@ scrollBy(dx: Length, dy: Length): void ...@@ -163,14 +161,15 @@ scrollBy(dx: Length, dy: Length): void
## 示例 ## 示例
### 示例1
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct ScrollExample { struct ScrollExample {
scroller: Scroller = new Scroller() scroller: Scroller = new Scroller();
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
build() { build() {
Stack({ alignContent: Alignment.TopStart }) { Stack({ alignContent: Alignment.TopStart }) {
...@@ -188,38 +187,39 @@ struct ScrollExample { ...@@ -188,38 +187,39 @@ struct ScrollExample {
}, item => item) }, item => item)
}.width('100%') }.width('100%')
} }
.scrollable(ScrollDirection.Vertical) .scrollable(ScrollDirection.Vertical) // 滚动方向纵向
.scrollBar(BarState.On) .scrollBar(BarState.On) // 滚动条常驻显示
.scrollBarColor(Color.Gray) .scrollBarColor(Color.Gray) // 滚动条颜色
.scrollBarWidth(30) .scrollBarWidth(30) // 滚动条宽度
.edgeEffect(EdgeEffect.None)
.onScroll((xOffset: number, yOffset: number) => { .onScroll((xOffset: number, yOffset: number) => {
console.info(xOffset + ' ' + yOffset) console.info(xOffset + ' ' + yOffset);
}) })
.onScrollEdge((side: Edge) => { .onScrollEdge((side: Edge) => {
console.info('To the edge') console.info('To the edge');
}) })
.onScrollEnd(() => { .onScrollEnd(() => {
console.info('Scroll Stop') console.info('Scroll Stop');
}) })
Button('scroll 150') Button('scroll 150')
.onClick(() => { // 点击后下滑指定距离150.0vp .onClick(() => { // 点击后下滑指定距离150.0vp
this.scroller.scrollBy(0,150) this.scroller.scrollBy(0,150);
}) })
.margin({ top: 10, left: 20 }) .margin({ top: 10, left: 20 })
Button('scroll 100') Button('scroll 100')
.onClick(() => { // 点击后滑动到指定位置,即下滑100.0vp的距离 .onClick(() => { // 点击后滑动到指定位置,即下滑100.0vp的距离
this.scroller.scrollTo({ xOffset: 0, yOffset: this.scroller.currentOffset().yOffset + 100 }) this.scroller.scrollTo({ xOffset: 0, yOffset: this.scroller.currentOffset().yOffset + 100 });
}) })
.margin({ top: 60, left: 20 }) .margin({ top: 60, left: 20 })
Button('back top') Button('back top')
.onClick(() => { // 点击后回到顶部 .onClick(() => { // 点击后回到顶部
this.scroller.scrollEdge(Edge.Top) this.scroller.scrollEdge(Edge.Top);
}) })
.margin({ top: 110, left: 20 }) .margin({ top: 110, left: 20 })
Button('next page') Button('next page')
.onClick(() => { // 点击后滑到下一页 .onClick(() => { // 点击后滑到下一页
this.scroller.scrollPage({ next: true }) this.scroller.scrollPage({ next: true });
}) })
.margin({ top: 170, left: 20 }) .margin({ top: 170, left: 20 })
}.width('100%').height('100%').backgroundColor(0xDCDCDC) }.width('100%').height('100%').backgroundColor(0xDCDCDC)
...@@ -229,14 +229,14 @@ struct ScrollExample { ...@@ -229,14 +229,14 @@ struct ScrollExample {
![zh-cn_image_0000001174104386](figures/zh-cn_image_0000001174104386.gif) ![zh-cn_image_0000001174104386](figures/zh-cn_image_0000001174104386.gif)
### 示例2
```ts ```ts
@Entry @Entry
@Component @Component
struct NestedScroll { struct NestedScroll {
@State listPosition: number = 0 // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。 @State listPosition: number = 0; // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。
private arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] private arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
private scroller: Scroller = new Scroller() private scroller: Scroller = new Scroller();
build() { build() {
Flex() { Flex() {
...@@ -257,18 +257,18 @@ struct NestedScroll { ...@@ -257,18 +257,18 @@ struct NestedScroll {
} }
.width("100%").height("50%").edgeEffect(EdgeEffect.None) .width("100%").height("50%").edgeEffect(EdgeEffect.None)
.onReachStart(() => { .onReachStart(() => {
this.listPosition = 0 this.listPosition = 0;
}) })
.onReachEnd(() => { .onReachEnd(() => {
this.listPosition = 2 this.listPosition = 2;
}) })
.onScrollBegin((dx: number, dy: number) => { .onScrollBegin((dx: number, dy: number) => {
if ((this.listPosition == 0 && dy >= 0) || (this.listPosition == 2 && dy <= 0)) { if ((this.listPosition == 0 && dy >= 0) || (this.listPosition == 2 && dy <= 0)) {
this.scroller.scrollBy(0, -dy) this.scroller.scrollBy(0, -dy);
return { dxRemain: dx, dyRemain: 0 } return { dxRemain: dx, dyRemain: 0 };
} }
this.listPosition = 1; this.listPosition = 1;
return { dxRemain: dx, dyRemain: dy } return { dxRemain: dx, dyRemain: dy };
}) })
Text("Scroll Area") Text("Scroll Area")
......
# 栅格设置 # 栅格设置
> **说明:** > **说明:**
> - 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 >
> > - 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
> - 栅格布局的列宽、列间距由距离最近的GridContainer父组件决定。使用栅格属性的组件树上至少需要有1个GridContainer容器组件。 >
> - 栅格布局的列宽、列间距由距离最近的GridContainer父组件决定。使用栅格属性的组件树上至少需要有1个GridContainer容器组件。
## 属性 ## 属性
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| ----------- | --------------------------| ----------------------------------------------- | | ----------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| useSizeType | {<br/>xs?:&nbsp;number&nbsp;\|&nbsp;{&nbsp;span:&nbsp;number,&nbsp;offset:&nbsp;number&nbsp;},<br/>sm?:&nbsp;number&nbsp;\|&nbsp;{&nbsp;span:&nbsp;number,&nbsp;offset:&nbsp;number&nbsp;},<br/>md?:&nbsp;number&nbsp;\|&nbsp;{&nbsp;span:&nbsp;number,&nbsp;offset:&nbsp;number&nbsp;},<br/>lg?:&nbsp;number&nbsp;\|&nbsp;{&nbsp;span:&nbsp;number,&nbsp;offset:&nbsp;number&nbsp;}<br/>} | 设置在特定设备宽度类型下的占用列数和偏移列数,span:&nbsp;占用列数;&nbsp;offset:&nbsp;偏移列数。<br/>当值为number类型时,仅设置列数,&nbsp;当格式如{"span":&nbsp;1,&nbsp;"offset":&nbsp;0}时,指同时设置占用列数与偏移列数。<br/>-&nbsp;xs:&nbsp;指设备宽度类型为SizeType.XS时的占用列数和偏移列数。<br/>-&nbsp;sm:&nbsp;指设备宽度类型为SizeType.SM时的占用列数和偏移列数。<br/>-&nbsp;md:&nbsp;指设备宽度类型为SizeType.MD时的占用列数和偏移列数。<br/>-&nbsp;lg:&nbsp;指设备宽度类型为SizeType.LG时的占用列数和偏移列数。 | | useSizeType | {<br/>xs?:&nbsp;number&nbsp;\|&nbsp;{&nbsp;span:&nbsp;number,&nbsp;offset:&nbsp;number&nbsp;},<br/>sm?:&nbsp;number&nbsp;\|&nbsp;{&nbsp;span:&nbsp;number,&nbsp;offset:&nbsp;number&nbsp;},<br/>md?:&nbsp;number&nbsp;\|&nbsp;{&nbsp;span:&nbsp;number,&nbsp;offset:&nbsp;number&nbsp;},<br/>lg?:&nbsp;number&nbsp;\|&nbsp;{&nbsp;span:&nbsp;number,&nbsp;offset:&nbsp;number&nbsp;}<br/>} | 设置在特定设备宽度类型下的占用列数和偏移列数,span:&nbsp;占用列数;&nbsp;offset:&nbsp;偏移列数。<br/>当值为number类型时,仅设置列数,&nbsp;当格式如{"span":&nbsp;1,&nbsp;"offset":&nbsp;0}时,指同时设置占用列数与偏移列数。<br/>-&nbsp;xs:&nbsp;指设备宽度类型为SizeType.XS时的占用列数和偏移列数。<br/>-&nbsp;sm:&nbsp;指设备宽度类型为SizeType.SM时的占用列数和偏移列数。<br/>-&nbsp;md:&nbsp;指设备宽度类型为SizeType.MD时的占用列数和偏移列数。<br/>-&nbsp;lg:&nbsp;指设备宽度类型为SizeType.LG时的占用列数和偏移列数。 |
| gridSpan | number | 默认占用列数,指useSizeType属性没有设置对应尺寸的列数(span)时,占用的栅格列数。<br/>**说明:**<br/>设置了栅格span属性,组件的宽度由栅格布局决定。<br>默认值:1 | | gridSpan | number | 默认占用列数,指useSizeType属性没有设置对应尺寸的列数(span)时,占用的栅格列数。<br/>**说明:**<br/>设置了栅格span属性,组件的宽度由栅格布局决定。<br>默认值:1 |
| gridOffset | number | 默认偏移列数,指useSizeType属性没有设置对应尺寸的偏移(offset)时,&nbsp;当前组件沿着父组件Start方向,偏移的列数,也就是当前组件位于第n列。<br/>**说明:**<br/>- 配置该属性后,当前组件在父组件水平方向的布局不再跟随父组件原有的布局方式,而是沿着父组件的Start方向偏移一定位移。<br/>- 偏移位移&nbsp;=&nbsp;(列宽&nbsp;+&nbsp;间距)\*&nbsp;列数。<br/>- 设置了偏移(gridOffset)的组件之后的兄弟组件会根据该组件进行相对布局,类似相对布局。<br>默认值:0 | | gridOffset | number | 默认偏移列数,指useSizeType属性没有设置对应尺寸的偏移(offset)时,&nbsp;当前组件沿着父组件Start方向,偏移的列数,也就是当前组件位于第n列。<br/>**说明:**<br/>- 配置该属性后,当前组件在父组件水平方向的布局不再跟随父组件原有的布局方式,而是沿着父组件的Start方向偏移一定位移。<br/>- 偏移位移&nbsp;=&nbsp;(列宽&nbsp;+&nbsp;间距)\*&nbsp;列数。<br/>- 设置了偏移(gridOffset)的组件之后的兄弟组件会根据该组件进行相对布局,类似相对布局。<br>默认值:0 |
## 示例 ## 示例
...@@ -23,42 +24,76 @@ ...@@ -23,42 +24,76 @@
@Entry @Entry
@Component @Component
struct GridContainerExample1 { struct GridContainerExample1 {
build() {
Column() {
Text('useSizeType').fontSize(15).fontColor(0xCCCCCC).width('90%')
GridContainer() {
Row({}) {
Row() {
Text('Left').fontSize(25)
}
.useSizeType({
xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 0 },
md: { span: 1, offset: 0 }, lg: { span: 2, offset: 0 }
})
.height("100%")
.backgroundColor(0x66bbb2cb)
build(){ Row() {
GridContainer() { Text('Center').fontSize(25)
Row({}) { }
Row() { .useSizeType({
Text('Left').fontSize(25) xs: { span: 1, offset: 0 }, sm: { span: 2, offset: 1 },
} md: { span: 5, offset: 1 }, lg: { span: 7, offset: 2 }
.useSizeType({ })
xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 0 }, .height("100%")
md: { span: 1, offset: 0 }, lg: { span: 2, offset: 0 } .backgroundColor(0x66b6c5d1)
})
.height("100%") Row() {
.backgroundColor(0x66bbb2cb) Text('Right').fontSize(25)
Row() { }
Text('Center').fontSize(25) .useSizeType({
xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 3 },
md: { span: 2, offset: 6 }, lg: { span: 3, offset: 9 }
})
.height("100%")
.backgroundColor(0x66bbb2cb)
} }
.useSizeType({ .height(200)
xs: { span: 1, offset: 0 }, sm: { span: 2, offset: 1 },
md: { span: 5, offset: 1 }, lg: { span: 7, offset: 2 } }
}) .backgroundColor(0xf1f3f5)
.height("100%") .margin({ top: 10 })
.backgroundColor(0x66b6c5d1)
// 单独设置组件的span和offset,在sm尺寸大小的设备上使用useSizeType中sm的数据实现一样的效果
Text('gridSpan,gridOffset').fontSize(15).fontColor(0xCCCCCC).width('90%')
GridContainer() {
Row() { Row() {
Text('Right').fontSize(25) Row() {
} Text('Left').fontSize(25)
.useSizeType({ }
xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 3 }, .gridSpan(1)
md: { span: 2, offset: 6 }, lg: { span: 3, offset: 9 } .height("100%")
}) .backgroundColor(0x66bbb2cb)
.height("100%")
.backgroundColor(0x66bbb2cb) Row() {
Text('Center').fontSize(25)
}
.gridSpan(2)
.gridOffset(1)
.height("100%")
.backgroundColor(0x66b6c5d1)
Row() {
Text('Right').fontSize(25)
}
.gridSpan(1)
.gridOffset(3)
.height("100%")
.backgroundColor(0x66bbb2cb)
}.height(200)
} }
.height(200)
} }
.backgroundColor(0xf1f3f5)
.margin({ top: 10 })
} }
} }
``` ```
...@@ -74,3 +109,7 @@ struct GridContainerExample1 { ...@@ -74,3 +109,7 @@ struct GridContainerExample1 {
**图3** 设备宽度为LG **图3** 设备宽度为LG
![zh-cn_image_0000001219982727](figures/zh-cn_image_0000001219982727.png) ![zh-cn_image_0000001219982727](figures/zh-cn_image_0000001219982727.png)
**图4** 单独设置gridSpan和gridOffset在特定屏幕大小下的效果与useSizeType效果一致
![gridSpan](figures/gridSpan.png)
\ No newline at end of file
# 图像效果 # 图像效果
例如背景模糊、内容模糊和灰度效果等 设置组件的模糊,阴影效果以及设置图片的图像效果
> **说明:** > **说明:**
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 属性 ## 属性
...@@ -18,63 +13,113 @@ ...@@ -18,63 +13,113 @@
| ----------------------------- | ------------------------------------------------------------ | ------ | ------------------------------------------------------------ | | ----------------------------- | ------------------------------------------------------------ | ------ | ------------------------------------------------------------ |
| blur | number | - | 为当前组件添加内容模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。 | | blur | number | - | 为当前组件添加内容模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。 |
| backdropBlur | number | - | 为当前组件添加背景模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。 | | backdropBlur | number | - | 为当前组件添加背景模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。 |
| shadow | {<br/>radius:&nbsp;number \| [Resource](ts-types.md#resource),<br/>color?:&nbsp;Color \| string \| Resource,<br/>offsetX?:&nbsp;number \| Resource,<br/>offsetY?:&nbsp;number \| Resource<br/>} | - | 为当前组件添加阴影效果,入参为模糊半径(必填)、阴影的颜色(可选,默认为灰色)、X轴的偏移量(可选,默认为0),Y轴的偏移量(可选,默认为0),偏移量单位为px。 | | shadow | {<br/>radius:&nbsp;number \| [Resource](ts-types.md#resource),<br/>color?:&nbsp;[Color](ts-appendix-enums.md#color) \| string \| [Resource](ts-types.md#resource),<br/>offsetX?:&nbsp;number \| [Resource](ts-types.md#resource),<br/>offsetY?:&nbsp;number \| [Resource](ts-types.md#resource)<br/>} | - | 为当前组件添加阴影效果,入参为模糊半径(必填)、阴影的颜色(可选,默认为灰色)、X轴的偏移量(可选,默认为0),Y轴的偏移量(可选,默认为0),偏移量单位为px。 |
| grayscale | number | 0.0 | 为当前组件添加灰度效果。值定义为灰度转换的比例,入参1.0则完全转为灰度图像,入参则0.0图像无变化,入参在0.0和1.0之间时,效果呈线性变化。(百分比) | | grayscale | number | 0.0 | 为当前组件添加灰度效果。值定义为灰度转换的比例,入参1.0则完全转为灰度图像,入参则0.0图像无变化,入参在0.0和1.0之间时,效果呈线性变化。(百分比) |
| brightness | number | 1.0 | 为当前组件添加高光效果,入参为高光比例,值为1时没有效果,小于1时亮度变暗,0为全黑;大于1时亮度增加,数值越大亮度越大。 | | brightness | number | 1.0 | 为当前组件添加高光效果,入参为高光比例,值为1时没有效果,小于1时亮度变暗,0为全黑;大于1时亮度增加,数值越大亮度越大。 |
| saturate | number | 1.0 | 为当前组件添加饱和度效果,饱和度为颜色中的含色成分和消色成分(灰)的比例,入参为1时,显示原图像,大于1时含色成分越大,饱和度越大;小于1时消色成分越大,饱和度越小。(百分比) | | saturate | number | 1.0 | 为当前组件添加饱和度效果,饱和度为颜色中的含色成分和消色成分(灰)的比例,入参为1时,显示原图像,大于1时含色成分越大,饱和度越大;小于1时消色成分越大,饱和度越小。(百分比) |
| contrast | number | 1.0 | 为当前组件添加对比度效果,入参为对比度的值,值为1时,显示原图;大于1时,值越大对比度越高,图像越清晰醒目;小于1时,值越小对比度越低;当对比度为0时,图像变为全灰。(百分比) | | contrast | number | 1.0 | 为当前组件添加对比度效果,入参为对比度的值,值为1时,显示原图;大于1时,值越大对比度越高,图像越清晰醒目;小于1时,值越小对比度越低;当对比度为0时,图像变为全灰。(百分比) |
| invert | number | 0 | 反转输入的图像。入参为图像反转的比例。值为1时完全反转。值为0则图像无变化。(百分比) | | invert | number | 0 | 反转输入的图像。入参为图像反转的比例。值为1时完全反转。值为0则图像无变化。(百分比) |
| colorBlend&nbsp;<sup>8+</sup> | Color&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | - | 为当前组件添加颜色叠加效果,入参为叠加的颜色。 | | colorBlend&nbsp;<sup>8+</sup> | [Color](ts-appendix-enums.md#color)&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | - | 为当前组件添加颜色叠加效果,入参为叠加的颜色。 |
| sepia | number | 0 | 将图像转换为深褐色。入参为图像反转的比例。值为1则完全是深褐色的,值为0图像无变化。&nbsp;(百分比) | | sepia | number | 0 | 将图像转换为深褐色。入参为图像反转的比例。值为1则完全是深褐色的,值为0图像无变化。&nbsp;(百分比) |
| hueRotate | number\|string | '0deg' | 色相旋转效果,输入参数为旋转角度。 | | hueRotate | number&nbsp;\|&nbsp;string | '0deg' | 色相旋转效果,输入参数为旋转角度。 |
## 示例 ## 示例
示例效果请以真机运行为准,当前IDE预览器不支持。 ### 示例1
模糊属性的用法,blur内容模糊,backdropBlur背景模糊。
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct ImageEffectsExample { struct BlurEffectsExample {
build() { build() {
Column({space: 10}) { Column({ space: 10 }) {
// 对字体进行模糊 // 对字体进行模糊
Text('font blur').fontSize(15).fontColor(0xCCCCCC).width('90%') Text('font blur').fontSize(15).fontColor(0xCCCCCC).width('90%')
Text('text').blur(3).width('90%').height(40) Flex({ alignItems: ItemAlign.Center }) {
.fontSize(16).backgroundColor(0xF9CF93).padding({ left: 5 }) Text('original text').margin(10)
Text('blur text')
.blur(1).margin(10)
Text('blur text')
.blur(2).margin(10)
Text('blur text')
.blur(3).margin(10)
}.width('90%').height(40)
.backgroundColor(0xF9CF93)
// 对背景进行模糊 // 对背景进行模糊
Text('backdropBlur').fontSize(15).fontColor(0xCCCCCC).width('90%') Text('backdropBlur').fontSize(15).fontColor(0xCCCCCC).width('90%')
Text().width('90%').height(40).fontSize(16).backdropBlur(3) Text()
.backgroundImage('/comment/bg.jpg') .width('90%')
.height(40)
.fontSize(16)
.backdropBlur(3)
.backgroundImage('/pages/attrs/image/image.jpg')
.backgroundImageSize({ width: 1200, height: 160 }) .backgroundImageSize({ width: 1200, height: 160 })
}.width('100%').margin({ top: 5 })
}
}
```
![textblur](figures/textblur.png)
### 示例2
设置图片的效果,包括阴影,灰度,高光,饱和度,对比度,图像反转,叠色,色相旋转等。
```ts
// xxx.ets
@Entry
@Component
struct ImageEffectsExample {
build() {
Column({ space: 10 }) {
// 添加阴影效果,图片效果不变
Text('shadow').fontSize(15).fontColor(0xCCCCCC).width('90%') Text('shadow').fontSize(15).fontColor(0xCCCCCC).width('90%')
Image($r('app.media.bg')).width('90%').height(40) Image($r('app.media.image'))
.shadow({ radius: 10, color: Color.Gray, offsetX: 5, offsetY: 5 }) .width('90%')
.height(40)
.shadow({ radius: 10, color: Color.Green, offsetX: 20, offsetY: 30 })
// 灰度效果0~1,越接近1,灰度越明显
Text('grayscale').fontSize(15).fontColor(0xCCCCCC).width('90%') Text('grayscale').fontSize(15).fontColor(0xCCCCCC).width('90%')
Image($r('app.media.bg')).width('90%').height(40).grayscale(0.6) Image($r('app.media.image')).width('90%').height(40).grayscale(0.3)
Image($r('app.media.image')).width('90%').height(40).grayscale(0.8)
// 高光效果,1为正常图片,<1变暗,>1亮度增大
Text('brightness').fontSize(15).fontColor(0xCCCCCC).width('90%') Text('brightness').fontSize(15).fontColor(0xCCCCCC).width('90%')
Image($r('app.media.bg')).width('90%').height(40).brightness(2.0) Image($r('app.media.image')).width('90%').height(40).brightness(1.2)
// 饱和度,原图为1
Text('saturate').fontSize(15).fontColor(0xCCCCCC).width('90%') Text('saturate').fontSize(15).fontColor(0xCCCCCC).width('90%')
Image($r('app.media.bg')).width('90%').height(40).saturate(2.0) Image($r('app.media.image')).width('90%').height(40).saturate(2.0)
Image($r('app.media.image')).width('90%').height(40).saturate(0.7)
// 对比度,1为原图,>1值越大越清晰,<1值越小越模糊
Text('contrast').fontSize(15).fontColor(0xCCCCCC).width('90%') Text('contrast').fontSize(15).fontColor(0xCCCCCC).width('90%')
Image($r('app.media.bg')).width('90%').height(40).contrast(2.0) Image($r('app.media.image')).width('90%').height(40).contrast(2.0)
Image($r('app.media.image')).width('90%').height(40).contrast(0.8)
// 图像反转比例
Text('invert').fontSize(15).fontColor(0xCCCCCC).width('90%') Text('invert').fontSize(15).fontColor(0xCCCCCC).width('90%')
Image($r('app.media.bg')).width('90%').height(40).invert(1) Image($r('app.media.image')).width('90%').height(40).invert(0.2)
Image($r('app.media.image')).width('90%').height(40).invert(0.8)
// 叠色添加
Text('colorBlend').fontSize(15).fontColor(0xCCCCCC).width('90%')
Image($r('app.media.image')).width('90%').height(40).colorBlend(Color.Green)
Image($r('app.media.image')).width('90%').height(40).colorBlend(Color.Blue)
// 深褐色
Text('sepia').fontSize(15).fontColor(0xCCCCCC).width('90%')
Image($r('app.media.image')).width('90%').height(40).sepia(0.8)
// 色相旋转
Text('hueRotate').fontSize(15).fontColor(0xCCCCCC).width('90%') Text('hueRotate').fontSize(15).fontColor(0xCCCCCC).width('90%')
Image($r('app.media.bg')).width('90%').height(40).hueRotate(90) Image($r('app.media.image')).width('90%').height(40).hueRotate(90)
}.width('100%').margin({ top: 5 }) }.width('100%').margin({ top: 5 })
} }
} }
``` ```
<img src="figures/image-effect.png" alt="image-effect" /> ![imageeffect](figures/imageeffect.png)
\ No newline at end of file
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
| 名称 | 参数说明 | 描述 | | 名称 | 参数说明 | 描述 |
| --------------- | ------ | ---------------------------------------- | | --------------- | ------ | ---------------------------------------- |
| aspectRatio | number | 指定当前组件的宽高比。 | | aspectRatio | number | 指定当前组件的宽高比,aspectRatio = width/height。 |
| displayPriority | number | 设置当前组件在布局容器中显示的优先级,当父容器空间不足时,低优先级的组件会被隐藏。<br/>**说明:**<br/>仅在Row/Column/Flex(单行)容器组件中生效。 | | displayPriority | number | 设置当前组件在布局容器中显示的优先级,当父容器空间不足时,低优先级的组件会被隐藏。<br/>**说明:**<br/>仅在Row/Column/Flex(单行)容器组件中生效。 |
...@@ -22,29 +22,32 @@ ...@@ -22,29 +22,32 @@
@Entry @Entry
@Component @Component
struct AspectRatioExample { struct AspectRatioExample {
private children : string[] = ['1', '2', '3', '4', '5', '6'] private children: string[] = ['1', '2', '3', '4', '5', '6'];
build() { build() {
Column({space: 20}) { Column({ space: 20 }) {
Text('using container: row').fontSize(14).fontColor(0xCCCCCC).width('100%') Text('using container: row').fontSize(14).fontColor(0xCCCCCC).width('100%')
Row({space: 10}) { Row({ space: 10 }) {
ForEach(this.children, (item) => { ForEach(this.children, (item) => {
// 组件宽度 = 组件高度*1.5 = 90
Text(item) Text(item)
.backgroundColor(0xbbb2cb) .backgroundColor(0xbbb2cb)
.fontSize(20) .fontSize(20)
.aspectRatio(1.5) .aspectRatio(1.5)
.height(60) .height(60)
// 组件高度 = 组件宽度/1.5 = 60/1.5 = 40
Text(item) Text(item)
.backgroundColor(0xbbb2cb) .backgroundColor(0xbbb2cb)
.fontSize(20) .fontSize(20)
.aspectRatio(1.5) .aspectRatio(1.5)
.width(60) .width(60)
}, item=>item) }, item => item)
} }
.size({width: "100%", height: 100}) .size({ width: "100%", height: 100 })
.backgroundColor(0xd2cab3) .backgroundColor(0xd2cab3)
.clip(true) .clip(true)
// grid子元素width/height=3/2
Text('using container: grid').fontSize(14).fontColor(0xCCCCCC).width('100%') Text('using container: grid').fontSize(14).fontColor(0xCCCCCC).width('100%')
Grid() { Grid() {
ForEach(this.children, (item) => { ForEach(this.children, (item) => {
...@@ -54,12 +57,12 @@ struct AspectRatioExample { ...@@ -54,12 +57,12 @@ struct AspectRatioExample {
.fontSize(40) .fontSize(40)
.aspectRatio(1.5) .aspectRatio(1.5)
} }
}, item=>item) }, item => item)
} }
.columnsTemplate('1fr 1fr 1fr') .columnsTemplate('1fr 1fr 1fr')
.columnsGap(10) .columnsGap(10)
.rowsGap(10) .rowsGap(10)
.size({width: "100%", height: 165}) .size({ width: "100%", height: 165 })
.backgroundColor(0xd2cab3) .backgroundColor(0xd2cab3)
}.padding(10) }.padding(10)
} }
...@@ -74,40 +77,44 @@ struct AspectRatioExample { ...@@ -74,40 +77,44 @@ struct AspectRatioExample {
```ts ```ts
class ContainerInfo { class ContainerInfo {
label : string = '' label: string = '';
size : string = '' size: string = '';
} }
class ChildInfo { class ChildInfo {
text : string = '' text: string = '';
priority : number = 0 priority: number = 0;
} }
@Entry @Entry
@Component @Component
struct DisplayPriorityExample { struct DisplayPriorityExample {
private container : ContainerInfo[] = [ // 显示容器大小
{label: 'Big container', size: '90%'}, private container: ContainerInfo[] = [
{label: 'Middle container', size: '50%'}, { label: 'Big container', size: '90%' },
{label: 'Small container', size: '30%'} { label: 'Middle container', size: '50%' },
{ label: 'Small container', size: '30%' }
] ]
private children : ChildInfo[] = [ private children: ChildInfo[] = [
{text: '1\n(priority:2)', priority: 2}, { text: '1\n(priority:2)', priority: 2 },
{text: '2\n(priority:1)', priority: 1}, { text: '2\n(priority:1)', priority: 1 },
{text: '3\n(priority:3)', priority: 3}, { text: '3\n(priority:3)', priority: 3 },
{text: '4\n(priority:1)', priority: 1}, { text: '4\n(priority:1)', priority: 1 },
{text: '5\n(priority:2)', priority: 2} { text: '5\n(priority:2)', priority: 2 }
] ]
@State currentIndex : number = 0 @State currentIndex: number = 0;
build() { build() {
Column({space: 10}) { Column({ space: 10 }) {
// 切换父级容器大小
Button(this.container[this.currentIndex].label).backgroundColor(0x317aff) Button(this.container[this.currentIndex].label).backgroundColor(0x317aff)
.onClick((event: ClickEvent) => { .onClick(() => {
this.currentIndex = (this.currentIndex + 1) % this.container.length this.currentIndex = (this.currentIndex + 1) % this.container.length;
}) })
Flex({justifyContent: FlexAlign.SpaceBetween}) { // 通过变量设置Flex父容器宽度
ForEach(this.children, (item)=>{ Flex({ justifyContent: FlexAlign.SpaceBetween }) {
ForEach(this.children, (item) => {
// 使用displayPriority给子组件绑定显示优先级
Text(item.text) Text(item.text)
.width(120) .width(120)
.height(60) .height(60)
...@@ -115,11 +122,11 @@ struct DisplayPriorityExample { ...@@ -115,11 +122,11 @@ struct DisplayPriorityExample {
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
.backgroundColor(0xbbb2cb) .backgroundColor(0xbbb2cb)
.displayPriority(item.priority) .displayPriority(item.priority)
}, item=>item.text) }, item => item.text)
} }
.width(this.container[this.currentIndex].size) .width(this.container[this.currentIndex].size)
.backgroundColor(0xd2cab3) .backgroundColor(0xd2cab3)
}.width("100%").margin({top:50}) }.width("100%").margin({ top: 50 })
} }
} }
......
...@@ -12,25 +12,25 @@ ...@@ -12,25 +12,25 @@
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| align | [Alignment](ts-appendix-enums.md#alignment) | 设置元素内容的对齐方式,只有当设置的width和height大小超过元素本身内容大小时生效。<br/>默认值:Alignment.Center | | align | [Alignment](ts-appendix-enums.md#alignment) | 设置元素内容的对齐方式,当元素的width和height大小大于元素本身内容大小时生效。<br/>默认值:Alignment.Center |
| direction | [Direction](ts-appendix-enums.md#direction) | 设置元素水平方向的布局。<br/>默认值:Direction.Auto | | direction | [Direction](ts-appendix-enums.md#direction) | 设置元素水平方向的布局。<br/>默认值:Direction.Auto |
| position | [Position](ts-types.md#position8) | 使用绝对定位,设置元素锚点相对于父容器顶部起点偏移位置。在布局容器中,设置该属性不影响父容器布局,仅在绘制时进行位置调整。 | | position | [Position](ts-types.md#position8) | 绝对定位,设置元素左上角相对于父容器左上角偏移位置。在布局容器中,设置该属性不影响父容器布局,仅在绘制时进行位置调整。 |
| markAnchor | [Position](ts-types.md#position8) | 设置元素在位置定位时的锚点,以元素顶部起点作为基准点进行偏移。<br/>默认值:<br/>{<br/>x: 0,<br/>y: 1<br/>} | | markAnchor | [Position](ts-types.md#position8) | 设置元素在位置定位时的锚点,以元素左上角作为基准点进行偏移。通常配合position和offset属性使用,单独使用时,效果类似offset<br/>默认值:<br/>{<br/>x: 0,<br/>y: 0<br/>} |
| offset | [Position](ts-types.md#position8) | 相对布局完成位置坐标偏移量,设置该属性,不影响父容器布局,仅在绘制时进行位置调整。<br/>默认值:<br/>{<br/>x: 0,<br/>y: 1<br/>} | | offset | [Position](ts-types.md#position8) | 相对定位,设置元素相对于自身的偏移量。设置该属性,不影响父容器布局,仅在绘制时进行位置调整。<br/>默认值:<br/>{<br/>x: 0,<br/>y: 0<br/>} |
| alignRules<sup>9+</sup> | {<br/>left?: { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) };<br/>right?: { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) };<br/>middle?: { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) };<br/>top?: { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) };<br/>bottom?: { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) };<br/>center?: { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) }<br/>} | 指定相对容器的对齐规则。<br/>-&nbsp;left:设置左对齐参数。<br/>-&nbsp;right:设置右对齐参数。<br/>-&nbsp;middle:设置中间对齐的参数。<br/>-&nbsp;top:设置顶部对齐的参数。<br/>-&nbsp;bottom:设置底部对齐的参数。<br/>-&nbsp;center:设置中心对齐的参数。<br/>**说明:**<br/>-&nbsp;anchor:设置作为锚点的组件的id值。<br>-&nbsp;align:设置相对于锚点组件的对齐方式。 | | alignRules<sup>9+</sup> | {<br/>left?: { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) };<br/>right?: { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) };<br/>middle?: { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) };<br/>top?: { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) };<br/>bottom?: { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) };<br/>center?: { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) }<br/>} | 指定相对容器的对齐规则。<br/>-&nbsp;left:设置左对齐参数。<br/>-&nbsp;right:设置右对齐参数。<br/>-&nbsp;middle:设置中间对齐的参数。<br/>-&nbsp;top:设置顶部对齐的参数。<br/>-&nbsp;bottom:设置底部对齐的参数。<br/>-&nbsp;center:设置中心对齐的参数。<br/>**说明:**<br/>-&nbsp;anchor:设置作为锚点的组件的id值。<br>-&nbsp;align:设置相对于锚点组件的对齐方式。 |
## 示例 ## 示例
### 示例1
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct PositionExample { struct PositionExample1 {
build() { build() {
Column() { Column() {
Column({space: 10}) { Column({ space: 10 }) {
// 元素内容<元素宽高,设置内容在与元素内的对齐方式
Text('align').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('align').fontSize(9).fontColor(0xCCCCCC).width('90%')
Text('top start') Text('top start')
.align(Alignment.TopStart) .align(Alignment.TopStart)
...@@ -39,6 +39,14 @@ struct PositionExample { ...@@ -39,6 +39,14 @@ struct PositionExample {
.fontSize(16) .fontSize(16)
.backgroundColor(0xFFE4C4) .backgroundColor(0xFFE4C4)
Text('Bottom end')
.align(Alignment.BottomEnd)
.height(50)
.width('90%')
.fontSize(16)
.backgroundColor(0xFFE4C4)
// 父容器设置direction为Direction.Auto|Ltr|不设置,子元素从左到右排列
Text('direction').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('direction').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row() { Row() {
Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3) Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3)
...@@ -47,6 +55,15 @@ struct PositionExample { ...@@ -47,6 +55,15 @@ struct PositionExample {
Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C) Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C)
} }
.width('90%') .width('90%')
.direction(Direction.Auto)
// 父容器设置direction为Direction.Rtl,子元素从右到左排列
Row() {
Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3)
Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C)
Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3)
Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C)
}
.width('90%')
.direction(Direction.Rtl) .direction(Direction.Rtl)
} }
} }
...@@ -55,54 +72,75 @@ struct PositionExample { ...@@ -55,54 +72,75 @@ struct PositionExample {
} }
``` ```
![zh-cn_image_0000001174264368](figures/zh-cn_image_0000001174264368.gif) ![align.png](figures/align.png)
### 示例2
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct PositionExample2 { struct PositionExample2 {
build() { build() {
Column({ space: 20 }) { Column({ space: 20 }) {
// 设置子组件左上角相对于父组件左上角的偏移位置
Text('position').fontSize(12).fontColor(0xCCCCCC).width('90%') Text('position').fontSize(12).fontColor(0xCCCCCC).width('90%')
Row({ space: 20 }) { Row() {
Text('1').size({ width: '45%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }) .fontSize(16) Text('1').size({ width: '30%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
Text('2 position(25, 15)') Text('2 position(30, 10)')
.size({ width: '60%', height: '30' }).backgroundColor(0xbbb2cb).border({ width: 1 }) .size({ width: '60%', height: '30' })
.fontSize(16).align(Alignment.Start) .backgroundColor(0xbbb2cb)
.position({ x: 25, y: 15 }) .border({ width: 1 })
.fontSize(16)
.align(Alignment.Start)
.position({ x: 30, y: 10 })
Text('3').size({ width: '45%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) Text('3').size({ width: '45%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
Text('4 position(50%, 70%)') Text('4 position(50%, 70%)')
.size({ width: '50%', height: '50' }).backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(16) .size({ width: '50%', height: '50' })
.backgroundColor(0xbbb2cb)
.border({ width: 1 })
.fontSize(16)
.position({ x: '50%', y: '70%' }) .position({ x: '50%', y: '70%' })
}.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed }) }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed })
// 相对于起点偏移,其中x为最终定位点距离起点水平方向间距,x>0往左,反之向右。
// y为最终定位点距离起点垂直方向间距,y>0向上,反之向下
Text('markAnchor').fontSize(12).fontColor(0xCCCCCC).width('90%') Text('markAnchor').fontSize(12).fontColor(0xCCCCCC).width('90%')
Stack({ alignContent: Alignment.TopStart }) { Stack({ alignContent: Alignment.TopStart }) {
Row() Row()
.size({ width: '100', height: '100' }) .size({ width: '100', height: '100' })
.backgroundColor(0xdeb887) .backgroundColor(0xdeb887)
Image($r('app.media.ic_health_heart')) Text('text')
.size({ width: 25, height: 25 }) .size({ width: 25, height: 25 })
.backgroundColor(Color.Green)
.markAnchor({ x: 25, y: 25 }) .markAnchor({ x: 25, y: 25 })
Image($r('app.media.ic_health_heart')) Text('text')
.size({ width: 25, height: 25 }) .size({ width: 25, height: 25 })
.markAnchor({ x: 25, y: 25 }) .backgroundColor(Color.Green)
.position({ x: '100%', y: '100%' }) .markAnchor({ x: -100, y: -25 })
Text('text')
.size({ width: 25, height: 25 })
.backgroundColor(Color.Green)
.markAnchor({ x: 25, y: -25 })
}.margin({ top: 25 }).border({ width: 1, style: BorderStyle.Dashed }) }.margin({ top: 25 }).border({ width: 1, style: BorderStyle.Dashed })
// 相对定位,x>0向右偏移,反之向左,y>0向下偏移,反之向上
Text('offset').fontSize(12).fontColor(0xCCCCCC).width('90%') Text('offset').fontSize(12).fontColor(0xCCCCCC).width('90%')
Row() { Row() {
Text('1').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) Text('1').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
Text('2\noffset(15, 15)') Text('2 offset(15, 30)')
.size({ width: 120, height: '50' }).backgroundColor(0xbbb2cb).border({ width: 1 }) .size({ width: 120, height: '50' })
.fontSize(16).align(Alignment.Start) .backgroundColor(0xbbb2cb)
.offset({ x: 15, y: 15 }) .border({ width: 1 })
.fontSize(16)
.align(Alignment.Start)
.offset({ x: 15, y: 30 })
Text('3').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) Text('3').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16)
Text('4\noffset(-10%, 20%)') Text('4 offset(-10%, 20%)')
.size({ width: 150, height: '50' }) .backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(16) .size({ width: 100, height: '50' })
.offset({ x: '-10%', y: '20%' }) .backgroundColor(0xbbb2cb)
.border({ width: 1 })
.fontSize(16)
.offset({ x: '-5%', y: '20%' })
}.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed }) }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed })
} }
.width('100%').margin({ top: 25 }) .width('100%').margin({ top: 25 })
...@@ -110,4 +148,4 @@ struct PositionExample2 { ...@@ -110,4 +148,4 @@ struct PositionExample2 {
} }
``` ```
![zh-cn_image_0000001174104392](figures/zh-cn_image_0000001174104392.gif) ![position.png](figures/position.png)
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| ---------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | ---------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| bindMenu | Array<MenuItem&gt;&nbsp;\|&nbsp;[CustomBuilder](ts-types.md#custombuilder8) | 给组件绑定菜单,点击后弹出菜单。弹出菜单项支持文本和自定义两种功能。 | | bindMenu | Array<[MenuItem](#menuitem)&gt;&nbsp;\|&nbsp;[CustomBuilder](ts-types.md#custombuilder8) | 给组件绑定菜单,点击后弹出菜单。弹出菜单项支持文本和自定义两种功能。 |
| bindContextMenu<sup>8+</sup> | content:&nbsp;[CustomBuilder](ts-types.md#custombuilder8),<br>responseType:&nbsp;[ResponseType](ts-appendix-enums.md#responsetype8) | 给组件绑定菜单,触发方式为长按或者右键点击,弹出菜单项需要自定义。 | | bindContextMenu<sup>8+</sup> | content:&nbsp;[CustomBuilder](ts-types.md#custombuilder8),<br>responseType:&nbsp;[ResponseType](ts-appendix-enums.md#responsetype8) | 给组件绑定菜单,触发方式为长按或者右键点击,弹出菜单项需要自定义。 |
## MenuItem ## MenuItem
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
## 属性 ## 属性
| 名称 | 参数类型 | 默认值 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | -------- | | ------- | ---------------------------------------- | ---------------------------------------- |
| opacity | number&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md#resource类型) | 1 | 元素的不透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。<br/>**说明:**<br/>子组件可以继承父组件的此属性。。 | | opacity | number&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 元素的不透明度,取值范围为0到1,1表示不透明,0表示完全透明, 达到隐藏组件效果,但是在布局中占位。<br>**说明:**<br/>子组件可以继承父组件的此属性。默认值:1 |
## 示例 ## 示例
...@@ -30,6 +30,10 @@ struct OpacityExample { ...@@ -30,6 +30,10 @@ struct OpacityExample {
Text().width('90%').height(50).opacity(0.7).backgroundColor(0xAFEEEE) Text().width('90%').height(50).opacity(0.7).backgroundColor(0xAFEEEE)
Text('opacity(0.4)').fontSize(9).width('90%').fontColor(0xCCCCCC) Text('opacity(0.4)').fontSize(9).width('90%').fontColor(0xCCCCCC)
Text().width('90%').height(50).opacity(0.4).backgroundColor(0xAFEEEE) Text().width('90%').height(50).opacity(0.4).backgroundColor(0xAFEEEE)
Text('opacity(0.1)').fontSize(9).width('90%').fontColor(0xCCCCCC)
Text().width('90%').height(50).opacity(0.1).backgroundColor(0xAFEEEE)
Text('opacity(0)').fontSize(9).width('90%').fontColor(0xCCCCCC)
Text().width('90%').height(50).opacity(0).backgroundColor(0xAFEEEE)
} }
.width('100%') .width('100%')
.padding({ top: 5 }) .padding({ top: 5 })
...@@ -37,4 +41,4 @@ struct OpacityExample { ...@@ -37,4 +41,4 @@ struct OpacityExample {
} }
``` ```
![zh-cn_image_0000001219662647](figures/zh-cn_image_0000001219662647.gif) ![opacity.png](figures/opacity.png)
...@@ -8,10 +8,9 @@ ...@@ -8,10 +8,9 @@
## 属性 ## 属性
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 默认值 | 描述 |
| ------- | ----------------------------- | ------------------------- | | -------- | -------- | -------- | -------- |
| overlay | value:&nbsp;string,<br/>options?:&nbsp;{<br/>align?:&nbsp;[Alignment](ts-appendix-enums.md#alignment),&nbsp;<br/>offset?:&nbsp;{<br> x?:&nbsp;number,<br> y?:&nbsp;number<br> }<br/>} | 在当前组件上,增加遮罩文本,布局与当前组件相同。<br>默认值:<br>{<br/>align:&nbsp;Alignment.Center,<br/>offset:&nbsp;{0,&nbsp;0}<br/>} | | overlay | value:&nbsp;string,<br/>options?:&nbsp;{<br/>align?:&nbsp;[Alignment](ts-appendix-enums.md#alignment),&nbsp;<br/>offset?:&nbsp;{x?:&nbsp;number, y?:&nbsp;number}<br/>} | {<br/>align:&nbsp;Alignment.Center,<br/>offset:&nbsp;{0,&nbsp;0}<br/>} | 在当前组件上,增加遮罩文本。<br/> value: 遮罩文本内容。<br/>options: 文本定位,align设置文本相对于组件的方位,[offset](ts-universal-attributes-location.md)为文本基于自身左上角的偏移量。文本默认处于组件左上角。<br>两者都设置时效果重叠,文本相对于组件方位定位后再基于当前位置文本的左上角进行偏移。 |
## 示例 ## 示例
...@@ -28,7 +27,10 @@ struct OverlayExample { ...@@ -28,7 +27,10 @@ struct OverlayExample {
Column() { Column() {
Image($r('app.media.img')) Image($r('app.media.img'))
.width(240).height(240) .width(240).height(240)
.overlay("Winter is a beautiful season, especially when it snows.", { align: Alignment.Bottom, offset: { x: 0, y: -15 } }) .overlay("Winter is a beautiful season, especially when it snows.", {
align: Alignment.Bottom,
offset: { x: 70, y: 100 }
})
}.border({ color: Color.Black, width: 2 }) }.border({ color: Color.Black, width: 2 })
}.width('100%') }.width('100%')
}.padding({ top: 20 }) }.padding({ top: 20 })
......
# Popup控制 # Popup控制
设置组件点击时弹出的气泡框状态。 给组件绑定popup弹窗,并设置弹窗内容,交互逻辑和显示状态。
> **说明:** > **说明:**
> >
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| ---------- | ------------------------------------- | --------------------------------------- | | ---------- | ------------------------------------- | --------------------------------------- |
| bindPopup | show:&nbsp;boolean,<br/>popup:&nbsp;PopupOptions&nbsp;\|&nbsp;CustomPopupOptions<sup>8+</sup> | 给组件绑定Popup,点击弹出弹窗。<br/>show:&nbsp;创建页面弹窗提示是否默认显示,默认值为false<br/>popup:&nbsp;配置当前弹窗提示的参数。 | | bindPopup | show:&nbsp;boolean,<br/>popup:&nbsp;[PopupOptions](#popupoptions类型说明)&nbsp;\|&nbsp;[CustomPopupOptions](#custompopupoptions8类型说明)<sup>8+</sup> | 给组件绑定Popup弹窗,设置参数show为true弹出弹框。<br/>show:&nbsp;弹窗显示状态,默认值为false,隐藏弹窗<br/>popup:&nbsp;配置当前弹窗提示的参数。 |
## PopupOptions类型说明 ## PopupOptions类型说明
...@@ -40,81 +40,80 @@ ...@@ -40,81 +40,80 @@
## 示例 ## 示例
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct PopupExample { struct PopupExample {
@State noHandlePopup: boolean = false @State handlePopup: boolean = false;
@State handlePopup: boolean = false @State customPopup: boolean = false;
@State customPopup: boolean = false
// popup构造器定义弹框内容
@Builder popupBuilder() { @Builder popupBuilder() {
Row({ space: 2 }) { Row({ space: 2 }) {
Image('/resource/ic_public_thumbsup.svg').width(24).height(24).margin({ left: -5 }) Image($r("app.media.image")).width(24).height(24).margin({ left: -5 })
Text('Custom Popup').fontSize(10) Text('Custom Popup').fontSize(10)
}.width(100).height(50).backgroundColor(Color.White) }.width(100).height(50).padding(5)
} }
build() { build() {
Flex({ direction: FlexDirection.Column }) { Flex({ direction: FlexDirection.Column }) {
Button('no handle popup') // PopupOptions 类型设置弹框内容
Button('PopupOptions')
.onClick(() => { .onClick(() => {
this.noHandlePopup = !this.noHandlePopup this.handlePopup = !this.handlePopup //点击展示弹框
})
.bindPopup(this.noHandlePopup, {
message: 'content1 content1',
placementOnTop: false,
onStateChange: (e) => {
console.info(e.isVisible.toString())
if (!e.isVisible) {
this.noHandlePopup = false
}
}
})
.position({ x: 100, y: 50 })
Button('with handle popup')
.onClick(() => {
this.handlePopup = !this.handlePopup
}) })
.bindPopup(this.handlePopup, { .bindPopup(this.handlePopup, {
message: 'content2 content2', message: 'This is a popup with PopupOptions',
placementOnTop: true, placementOnTop: false,
// 第一个按钮
primaryButton: { primaryButton: {
value: 'ok', value: 'confirm',
action: () => {
this.handlePopup = !this.handlePopup
console.info('ok Button click')
}
},
// 第二个按钮
secondaryButton: {
value: 'cancle',
action: () => { action: () => {
this.handlePopup = !this.handlePopup this.handlePopup = !this.handlePopup
console.info('secondaryButton click') console.info('cancle Button click')
} }
}, },
onStateChange: (e) => { onStateChange: (e) => {
console.info(e.isVisible.toString()) console.info(e.isVisible.toString())
if (!e.isVisible) {
this.handlePopup = false
}
} }
}) })
.position({ x: 100, y: 200 }) .position({ x: 100, y: 50 })
Button('custom popup') // CustomPopupOptions 类型设置弹框内容
Button('CustomPopupOptions')
.onClick(() => { .onClick(() => {
this.customPopup = !this.customPopup this.customPopup = !this.customPopup
}) })
.bindPopup(this.customPopup, { .bindPopup(this.customPopup, {
builder: this.popupBuilder, builder: this.popupBuilder,
placement: Placement.Bottom, placement: Placement.Top,
maskColor: 0x33000000, maskColor: 0x33000000,
popupColor: Color.White, popupColor: Color.Yellow,
enableArrow: true, enableArrow: true,
autoCancel: true,
onStateChange: (e) => { onStateChange: (e) => {
if (!e.isVisible) { if (!e.isVisible) {
this.customPopup = false this.customPopup = false
} }
} }
}) })
.position({ x: 100, y: 350 }) .position({ x: 80, y: 200 })
}.width('100%').padding({ top: 5 }) }.width('100%').padding({ top: 5 })
} }
} }
``` ```
![zh-cn_image_0000001187055946](figures/zh-cn_image_0000001187055946.gif) ![figures/popup.gif](figures/popup.gif)
# 尺寸设置 # 尺寸设置
用于设置组件的宽高、边距等显示尺寸进行设置 用于设置组件的宽高、边距。
> **说明:** > **说明:**
> >
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
| padding | [Padding](ts-types.md#padding)&nbsp;\|&nbsp;[Length](ts-types.md#length) | 设置内边距属性。<br/>参数为Length类型时,四个方向内边距同时生效。<br>默认值:0 <br>padding设置百分比时,上下左右内边距均以父容器的width作为基础值。 | | padding | [Padding](ts-types.md#padding)&nbsp;\|&nbsp;[Length](ts-types.md#length) | 设置内边距属性。<br/>参数为Length类型时,四个方向内边距同时生效。<br>默认值:0 <br>padding设置百分比时,上下左右内边距均以父容器的width作为基础值。 |
| margin | [Margin](ts-types.md#margin)&nbsp;\|&nbsp;[Length](ts-types.md#length) | 设置外边距属性。<br/>参数为Length类型时,四个方向外边距同时生效。<br>默认值:0 <br>margin设置百分比时,上下左右外边距均以父容器的width作为基础值。| | margin | [Margin](ts-types.md#margin)&nbsp;\|&nbsp;[Length](ts-types.md#length) | 设置外边距属性。<br/>参数为Length类型时,四个方向外边距同时生效。<br>默认值:0 <br>margin设置百分比时,上下左右外边距均以父容器的width作为基础值。|
| constraintSize | {<br/>minWidth?:&nbsp;[Length](ts-types.md#length),<br/>maxWidth?:&nbsp;[Length](ts-types.md#length),<br/>minHeight?:&nbsp;[Length](ts-types.md#length),<br/>maxHeight?:&nbsp;[Length](ts-types.md#length)<br/>} | 设置约束尺寸,组件布局时,进行尺寸范围限制。constraintSize的优先级高于Width和Height。<br>默认值:<br>{<br/>minWidth:&nbsp;0,<br/>maxWidth:&nbsp;Infinity,<br/>minHeight:&nbsp;0,<br/>maxHeight:&nbsp;Infinity<br/>} | | constraintSize | {<br/>minWidth?:&nbsp;[Length](ts-types.md#length),<br/>maxWidth?:&nbsp;[Length](ts-types.md#length),<br/>minHeight?:&nbsp;[Length](ts-types.md#length),<br/>maxHeight?:&nbsp;[Length](ts-types.md#length)<br/>} | 设置约束尺寸,组件布局时,进行尺寸范围限制。constraintSize的优先级高于Width和Height。<br>默认值:<br>{<br/>minWidth:&nbsp;0,<br/>maxWidth:&nbsp;Infinity,<br/>minHeight:&nbsp;0,<br/>maxHeight:&nbsp;Infinity<br/>} |
| layoutWeight | number&nbsp;\|&nbsp;string | 容器尺寸确定时,元素与兄弟节点主轴布局尺寸按照权重进行分配,忽略本身尺寸设置,表示自适应占满剩余空间。<br>**说明:**<br/>仅在Row/Column/Flex布局中生效。<br>默认值:0 | | layoutWeight | number&nbsp;\|&nbsp;string | 父容器尺寸确定时,设置了layoutWeight属性的子元素与兄弟元素占主轴尺寸按照权重进行分配,忽略元素本身尺寸设置,表示自适应占满剩余空间。<br>**说明:**<br/>仅在Row/Column/Flex布局中生效。|
## 示例 ## 示例
...@@ -31,30 +31,41 @@ struct SizeExample { ...@@ -31,30 +31,41 @@ struct SizeExample {
build() { build() {
Column({ space: 10 }) { Column({ space: 10 }) {
Text('margin and padding:').fontSize(12).fontColor(0xCCCCCC).width('90%') Text('margin and padding:').fontSize(12).fontColor(0xCCCCCC).width('90%')
// 宽度80 ,高度80 ,内外边距20
Row() { Row() {
// 宽度80 ,高度80 ,外边距20(蓝色区域),内边距10(白色区域)
Row() { Row() {
Row().size({ width: '100%', height: '100%' }).backgroundColor(0xAFEEEE) Row().size({ width: '100%', height: '100%' }).backgroundColor(Color.Yellow)
}.width(80).height(80).padding(20).margin(20).backgroundColor(0xFDF5E6) }
}.backgroundColor(0xFFA500) .width(80)
.height(80)
.padding(10)
.margin(20)
.backgroundColor(Color.White)
}.backgroundColor(Color.Blue)
Text('constraintSize').fontSize(12).fontColor(0xCCCCCC).width('90%')
Text('this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text')
.width('90%')
.constraintSize({ maxWidth: 200 })
Text('layoutWeight').fontSize(12).fontColor(0xCCCCCC).width('90%') Text('layoutWeight').fontSize(12).fontColor(0xCCCCCC).width('90%')
// 容器尺寸确定时,元素与兄弟节点主轴布局尺寸按照权重进行分配,忽略本身尺寸设置。 // 父容器尺寸确定时,设置了layoutWeight的子元素在主轴布局尺寸按照权重进行分配,忽略本身尺寸设置。
Row() { Row() {
// 权重1 // 权重1,占主轴剩余空间1/3
Text('layoutWeight(1)') Text('layoutWeight(1)')
.size({ width: '30%', height: 110 }).backgroundColor(0xFFEFD5).textAlign(TextAlign.Center) .size({ width: '30%', height: 110 }).backgroundColor(0xFFEFD5).textAlign(TextAlign.Center)
.layoutWeight(1) .layoutWeight(1)
// 权重2 // 权重2,占主轴剩余空间2/3
Text('layoutWeight(2)') Text('layoutWeight(2)')
.size({ width: '30%', height: 110 }).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) .size({ width: '30%', height: 110 }).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
.layoutWeight(2) .layoutWeight(2)
// 权重默认0 // 未设置layoutWeight属性,组件按照自身尺寸渲染
Text('no layoutWeight') Text('no layoutWeight')
.size({ width: '30%', height: 110 }).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) .size({ width: '30%', height: 110 }).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
}.size({ width: '90%', height: 140 }).backgroundColor(0xAFEEEE) }.size({ width: '90%', height: 140 }).backgroundColor(0xAFEEEE)
}.width('100%').margin({ top: 5 }) }.width('100%').margin({ top: 5 })
}} }
}
``` ```
![zh-cn_image_0000001174264384](figures/zh-cn_image_0000001174264384.gif) ![size](figures/size.png)
# 文本样式设置 # 文本样式设置
针对包含文本元素的组件,设置文本样式。
> **说明:** > **说明:**
> >
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
针对包含文本元素的组件,设置文本样式。
## 属性 ## 属性
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| -----------| ---------------------------------------- | ------------------------------------ | | -----------| ---------------------------------------- | ------------------------------------ |
| fontColor | [ResourceColor](ts-types.md#resourcecolor) | 设置文本颜色。 | | fontColor | [ResourceColor](ts-types.md#resourcecolor) | 设置字体颜色。 |
| fontSize | Length&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 设置文本尺寸,Length为number类型时,使用fp单位。 | | fontSize | Length&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 设置字体大小,Length为number类型时,使用fp单位。字体默认大小10。 |
| fontStyle | [FontStyle](ts-appendix-enums.md#fontstyle) | 设置文本的字体样式。<br>默认值:FontStyle.Normal | | fontStyle | [FontStyle](ts-appendix-enums.md#fontstyle) | 设置字体样式。<br>默认值:FontStyle.Normal |
| fontWeight | number&nbsp;\|&nbsp;[FontWeight](ts-appendix-enums.md#fontweight)&nbsp;\|&nbsp;string | 设置文本的字体粗细,number类型取值[100,&nbsp;900],取值间隔为100,默认为400,取值越大,字体越粗。string类型仅支持number类型取值的字符串形式,例如"400",以及"bold"、"bolder"、"lighter"、"regular"、"medium",分别对应FontWeight中相应的枚举值。<br/>默认值:FontWeight.Normal | | fontWeight | number&nbsp;\|&nbsp;[FontWeight](ts-appendix-enums.md#fontweight)&nbsp;\|&nbsp;string | 设置文本的字体粗细,number类型取值[100,&nbsp;900],取值间隔为100,默认为400,取值越大,字体越粗。string类型仅支持number类型取值的字符串形式,例如"400",以及"bold"、"bolder"、"lighter"、"regular"、"medium",分别对应FontWeight中相应的枚举值。<br/>默认值:FontWeight.Normal |
| fontFamily | string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 设置文本的字体列表。使用多个字体,使用','进行分割,优先级按顺序生效。例如:'Arial,&nbsp;sans-serif'。 | | fontFamily | string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 设置字体列表。默认字体'HarmonyOS Sans',且当前只支持这种字体。|
## 示例 ## 示例
...@@ -29,40 +30,38 @@ struct TextStyleExample { ...@@ -29,40 +30,38 @@ struct TextStyleExample {
build() { build() {
Column({ space: 5 }) { Column({ space: 5 }) {
Text('default text') Text('default text')
Divider()
Text('text font color red')
Text('text font color red').fontColor(Color.Red)
Divider()
Text('text font default')
Text('text font size 10').fontSize(10)
Text('text font size 10fp').fontSize('10fp')
Text('text font size 20').fontSize(20)
Divider()
Text('text font style Italic').fontStyle(FontStyle.Italic)
Divider()
Text('text fontWeight bold').fontWeight(700)
Text('text fontWeight lighter').fontWeight(FontWeight.Lighter)
Divider()
Text('red 20 Italic bold text')
.fontColor(Color.Red) .fontColor(Color.Red)
Text('text font size 20')
.fontSize(20) .fontSize(20)
Text('text font style Italic')
.fontStyle(FontStyle.Italic) .fontStyle(FontStyle.Italic)
.fontWeight(FontWeight.Bold)
Text('text fontWeight bold') Divider()
.fontWeight(700)
Text('Orange 18 Normal text')
Text('text fontFamily sans-serif')
.fontFamily('sans-serif')
Text('red 20 Italic bold cursive text')
.fontColor(Color.Red)
.fontSize(20)
.fontStyle(FontStyle.Italic)
.fontWeight(700)
.fontFamily('cursive')
.textAlign(TextAlign.Center)
.width('90%')
Text('Orange 18 Normal source-sans-pro text')
.fontColor(Color.Orange) .fontColor(Color.Orange)
.fontSize(18) .fontSize(18)
.fontStyle(FontStyle.Normal) .fontStyle(FontStyle.Normal)
.fontWeight(400)
.fontFamily('source-sans-pro,cursive,sans-serif')
}.width('100%') }.width('100%')
} }
} }
``` ```
![zh-cn_image_0000001219662673](figures/zh-cn_image_0000001219662673.png) ![textstyle](figures/textstyle.png)
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
适用于支持通用点击事件、通用触摸事件、通用手势处理的组件。 适用于支持通用点击事件、通用触摸事件、通用手势处理的组件。
> **说明:** > **说明:**
> >
> 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
...@@ -12,16 +13,16 @@ ...@@ -12,16 +13,16 @@
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| -------------- | --------------------------------------------- | ----------------------------------------- | | -------------- | --------------------------------------------- | ----------------------------------------- |
| responseRegion | Array&lt;Rectangle&gt;&nbsp;\|&nbsp;Rectangle | 设置一个或多个触摸热区,包括位置和大小。<br/>默认值:<br/>{<br/>x:0,<br/>y:0,<br/>width:'100%',<br/>height:'100%'<br/>} | | responseRegion | Array&lt;[Rectangle](#rectangle对象说明)&gt;&nbsp;\|&nbsp;[Rectangle](#rectangle对象说明) | 设置一个或多个触摸热区,包括位置和大小。<br/>默认触摸热区为整个组件,默认值:<br/>{<br/>x:0,<br/>y:0,<br/>width:'100%',<br/>height:'100%'<br/>} |
### Rectangle对象说明 ## Rectangle对象说明
| 名称 | 类型 | 必填 | 描述 | | 名称 | 类型 | 必填 | 描述 |
| ------ | ----------------------------- | -----| -------------------------------- | | ------ | ----------------------------- | -----| -------------------------------- |
| x | [Length](ts-types.md#length) | 否 | 触摸点相对于组件本身左边沿的X坐标。<br/>默认值:0vp | | x | [Length](ts-types.md#length) | 否 | 触摸点相对于组件左上角的x轴坐标。<br/>默认值:0vp |
| y | [Length](ts-types.md#length) | 否 | 触摸点相对于组件本身左边沿的Y坐标。<br/>默认值:0vp | | y | [Length](ts-types.md#length) | 否 | 触摸点相对于组件左上角的y轴坐标。<br/>默认值:0vp |
| width | [Length](ts-types.md#length) | 否 | 触摸热区范围的宽度。<br/>默认值:100% | | width | [Length](ts-types.md#length) | 否 | 触摸热区的宽度。<br/>默认值:'100%' |
| height | [Length](ts-types.md#length) | 否 | 触摸热区范围的高度。<br/>默认值:100% | | height | [Length](ts-types.md#length) | 否 | 触摸热区的高度。<br/>默认值:'100%' |
> **说明:** > **说明:**
> >
...@@ -29,7 +30,7 @@ ...@@ -29,7 +30,7 @@
> >
> width和height只能设置正值百分比。width:'100%'表示热区宽度设置为该组件本身的宽度。比如组件本身宽度是100vp,那么'100%'表示热区宽度也为100vp。height:'100%'表示热区高度设置为该组件本身的高度。 > width和height只能设置正值百分比。width:'100%'表示热区宽度设置为该组件本身的宽度。比如组件本身宽度是100vp,那么'100%'表示热区宽度也为100vp。height:'100%'表示热区高度设置为该组件本身的高度。
> >
> 百分比是相对于组件本身来度量的 > 百分比相对于组件自身宽高进行计算
## 示例 ## 示例
...@@ -38,19 +39,38 @@ ...@@ -38,19 +39,38 @@
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct ResponseRegionExample { struct TouchTargetExample {
@State text: string = "";
build() { build() {
Column() { Column({ space: 20 }) {
Toggle({ type: ToggleType.Checkbox, isOn: true }) Text("{x:0,y:0,width:'50%',height:'100%'}")
.selectedColor(0x39a2db) // 热区宽度为按钮的一半,点击右侧无响应
.backgroundColor(0xAFEEEE) Button("button1")
.responseRegion({ x: 1.0, y: 1.0, width: 400, height: 400 }) .responseRegion({ x: 0, y: 0, width: '50%', height: '100%' })
.onChange((isOn: boolean) => { .onClick(() => {
console.info('Component status:' + isOn) this.text = 'button1 clicked';
}) })
}.width('100%').margin({ top: 5 })
// 热区宽度为按钮的一半,且右移一个按钮宽度,点击button2右侧左边,点击事件生效
Text("{x:'100%',y:0,width:'50%',height:'100%'}")
Button("button2")
.responseRegion({ x: '100%', y: 0, width: '50%', height: '100%' })
.onClick(() => {
this.text = 'button2 clicked';
})
// 热区大小为整个按钮,且下移一个按钮高度,点击button3下方按钮大小区域,点击事件生效
Text("{x:0,y:'100%',width:'100%',height:'100%'}")
Button("button3")
.responseRegion({ x: 0, y: '100%', width: '100%', height: '100%' })
.onClick(() => {
this.text = 'button3 clicked';
})
Text(this.text).margin({ top: 50 })
}.width('100%').margin({ top: 10 })
} }
} }
``` ```
![zh-cn_image_0000001184400598](figures/zh-cn_image_0000001184400598.gif) ![touchtarget.gif](figures/touchtarget.gif)
...@@ -23,20 +23,21 @@ struct VisibilityExample { ...@@ -23,20 +23,21 @@ struct VisibilityExample {
build() { build() {
Column() { Column() {
Column() { Column() {
Text('Visible').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row().visibility(Visibility.Visible).width('90%').height(80).backgroundColor(0xAFEEEE)
Text('None').fontSize(9).width('90%').fontColor(0xCCCCCC)
// 隐藏不参与占位 // 隐藏不参与占位
Text('None').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row().visibility(Visibility.None).width('90%').height(80).backgroundColor(0xAFEEEE) Row().visibility(Visibility.None).width('90%').height(80).backgroundColor(0xAFEEEE)
Text('Hidden').fontSize(9).width('90%').fontColor(0xCCCCCC)
// 隐藏参与占位 // 隐藏参与占位
Text('Hidden').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row().visibility(Visibility.Hidden).width('90%').height(80).backgroundColor(0xAFEEEE) Row().visibility(Visibility.Hidden).width('90%').height(80).backgroundColor(0xAFEEEE)
// 正常显示,组件默认的显示模式
Text('Visible').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row().visibility(Visibility.Visible).width('90%').height(80).backgroundColor(0xAFEEEE)
}.width('90%').border({ width: 1 }) }.width('90%').border({ width: 1 })
}.width('100%').margin({ top: 5 }) }.width('100%').margin({ top: 5 })
} }
} }
``` ```
![zh-cn_image_0000001174104390](figures/zh-cn_image_0000001174104390.gif) ![visibility.png](figures/visibility.png)
# Z序控制 # Z序控制
组件的Z序,指明了该组件在堆叠组件中的位置 组件的Z序,设置组件的堆叠顺序
> **说明:** > **说明:**
> >
...@@ -25,20 +25,25 @@ struct ZIndexExample { ...@@ -25,20 +25,25 @@ struct ZIndexExample {
build() { build() {
Column() { Column() {
Stack() { Stack() {
// stack会重叠组件, 默认后定义的在最上面 // stack会重叠组件, 默认后定义的在最上面,具有较高zIndex值的元素在zIndex较小的元素前面
Text('first child, zIndex(2)') Text('1, zIndex(2)')
.size({width: '40%', height: '30%'}).backgroundColor(0xbbb2cb) .size({ width: '40%', height: '30%' }).backgroundColor(0xbbb2cb)
.zIndex(2) .zIndex(2)
// 默认值0 Text('2, default zIndex(1)')
Text('second child, default zIndex(0)') .size({ width: '70%', height: '50%' }).backgroundColor(0xd2cab3).align(Alignment.TopStart)
.size({width: '90%', height: '80%'}).backgroundColor(0xd2cab3).align(Alignment.TopStart)
Text('third child, zIndex(1)')
.size({width: '70%', height: '50%'}).backgroundColor(0xc1cbac).align(Alignment.TopStart)
.zIndex(1) .zIndex(1)
Text('3, zIndex(0)')
.size({ width: '90%', height: '80%' }).backgroundColor(0xc1cbac).align(Alignment.TopStart)
}.width('100%').height(200) }.width('100%').height(200)
}.width('100%').height(200) }.width('100%').height(200)
} }
} }
``` ```
Stack容器内子组件不设置zIndex的效果
![nozindex.png](figures/nozindex.png)
Stack容器子组件设置zIndex后效果
![zindex.png](figures/zindex.png)
![zh-cn_image_0000001174582860](figures/zh-cn_image_0000001174582860.png)
...@@ -42,4 +42,4 @@ struct AreaExample { ...@@ -42,4 +42,4 @@ struct AreaExample {
} }
``` ```
![zh-cn_image_0000001189634870](figures/zh-cn_image_0000001189634870.gif) ![zh-cn_image_0000001189634870](figures/zh-cn_image_0000001189634870.gif)
\ No newline at end of file
...@@ -57,4 +57,4 @@ struct KeyEventExample { ...@@ -57,4 +57,4 @@ struct KeyEventExample {
} }
``` ```
![zh-cn_image_0000001174264364](figures/zh-cn_image_0000001174264364.gif) ![zh-cn_image_0000001174264364](figures/zh-cn_image_0000001174264364.gif)
\ No newline at end of file
...@@ -72,4 +72,4 @@ export struct FoodList { ...@@ -72,4 +72,4 @@ export struct FoodList {
} }
} }
} }
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册