未验证 提交 d5c15100 编写于 作者: O openharmony_ci 提交者: Gitee

!12915 修改relativeContainer示例代码

Merge pull request !12915 from xiexiyun/relative_container
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* 子组件可以将容器或者其他子组件设为锚点: * 子组件可以将容器或者其他子组件设为锚点:
* 参与相对布局的容器内组件必须设置id,不设置id的组件不显示,容器id固定为__container__。 * 参与相对布局的容器内组件必须设置id,不设置id的组件不显示,容器id固定为__container__。
* 此子组件某一方向上的三个位置可以将容器或其他子组件的同方向三个位置为锚点,同方向上两个以上位置设置锚点以后会跳过第三个。 * 此子组件某一方向上的三个位置可以将容器或其他子组件的同方向三个位置为锚点,同方向上两个以上位置设置锚点以后会跳过第三个。
* 前端页面设置的子组件尺寸大小不会受到相对布局规则的影响。 * 前端页面设置的子组件尺寸大小不会受到相对布局规则的影响。子组件某个方向上设置两个或以上alignRules时不建议设置此方向尺寸大小。
* 对齐后需要额外偏移可设置offset。 * 对齐后需要额外偏移可设置offset。
* 特殊情况 * 特殊情况
* 互相依赖,环形依赖时容器内子组件全部不绘制。 * 互相依赖,环形依赖时容器内子组件全部不绘制。
...@@ -37,64 +37,67 @@ RelativeContainer() ...@@ -37,64 +37,67 @@ RelativeContainer()
@Entry @Entry
@Component @Component
struct Index { struct Index {
build() {
@Entry
@Component
struct Index {
build() { build() {
Row() { Row() {
Button("Extra button").width(100).height(50)
RelativeContainer() { RelativeContainer() {
Button("Button 1") Row().width(100).height(100)
.width(120) .backgroundColor("#FF3333")
.height(30)
.alignRules({ .alignRules({
middle: { anchor: "__container__", align: HorizontalAlign.Center }, top: {anchor: "__container__", align: VerticalAlign.Top},
left: {anchor: "__container__", align: HorizontalAlign.Start}
}) })
.id("bt1") .id("row1")
.borderWidth(1)
.borderColor(Color.Black)
Text("This is text 2") Row().width(100).height(100)
.fontSize(20) .backgroundColor("#FFCC00")
.padding(10)
.alignRules({ .alignRules({
bottom: { anchor: "__container__", align: VerticalAlign.Bottom }, top: {anchor: "__container__", align: VerticalAlign.Top},
top: { anchor: "bt1", align: VerticalAlign.Bottom }, right: {anchor: "__container__", align: HorizontalAlign.End}
right: { anchor: "bt1", align: HorizontalAlign.Center }
}) })
.id("tx2") .id("row2")
.borderWidth(1)
.borderColor(Color.Black) Row().height(100)
.height(30) .backgroundColor("#FF6633")
Button("Button 3")
.width(100)
.height(100)
.alignRules({ .alignRules({
left: { anchor: "bt1", align: HorizontalAlign.End }, top: {anchor: "row1", align: VerticalAlign.Bottom},
top: { anchor: "tx2", align: VerticalAlign.Center }, left: {anchor: "row1", align: HorizontalAlign.End},
bottom: { anchor: "__container__", align: VerticalAlign.Bottom } right: {anchor: "row2", align: HorizontalAlign.Start}
}) })
.id("bt3") .id("row3")
.borderWidth(1)
.borderColor(Color.Black)
Text("This is text 4") Row()
.fontSize(20) .backgroundColor("#FF9966")
.padding(10)
.alignRules({ .alignRules({
left: { anchor: "tx2", align: HorizontalAlign.End }, top: {anchor: "row3", align: VerticalAlign.Bottom},
right: { anchor: "__container__", align: HorizontalAlign.End }, bottom: {anchor: "__container__", align: VerticalAlign.Bottom},
top: { anchor: "__container__", align: VerticalAlign.Top }, left: {anchor: "__container__", align: HorizontalAlign.Start},
bottom: { anchor: "bt3", align: VerticalAlign.Top } right: {anchor: "row1", align: HorizontalAlign.End}
}) })
.id("tx4") .id("row4")
.borderWidth(1)
.borderColor(Color.Black) Row()
.backgroundColor("#FF66FF")
.alignRules({
top: {anchor: "row3", align: VerticalAlign.Bottom},
bottom: {anchor: "__container__", align: VerticalAlign.Bottom},
left: {anchor: "row2", align: HorizontalAlign.Start},
right: {anchor: "__container__", align: HorizontalAlign.End}
})
.id("row5")
} }
.width(200).height(200) .width(300).height(300)
.backgroundColor(Color.Orange) .margin({left: 100})
.border({width:2, color: "#6699FF"})
} }
.height('100%') .height('100%')
} }
}
}
} }
``` ```
![relative container](figures/relativecontainer.png) ![relative container](figures/relativecontainer.png)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册