#鸿蒙通关秘籍#如何在HarmonyOS NEXT中设置绝对布局?

HarmonyOS
2024-11-27 11:50:05
7626浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
hm673ff0a9c5234

在HarmonyOS NEXT中可以使用position属性来设置绝对布局。子组件的位置是相对于父容器设定的,以下代码将按钮置于父组件右下角:

@Entry
@Component
struct Index {
  build() {
    Column(){
      Button('按钮').position({
        right:0,
        bottom:0
      }).width(100).height(50)
    }.width('100%').height(500).backgroundColor(Color.Green).alignItems(HorizontalAlign.Start)
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

这里通过设置rightbottom0,按钮将紧贴父容器的右下角。

分享
微博
QQ
微信
回复
2024-11-27 13:10:16


相关问题