提交 942df330 编写于 作者: X xiexiyun

挑单monthly:修改relativeContainer示例代码

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