HarmonyOS Stack 里 align不生效?

@Entry
@Component
struct Index {
  icon: ResourceStr = $r("app.media.startIcon")

  build() {
    Stack() {
      Image(this.icon)
        .width(30)
        .height(30)
        .align(Alignment.TopStart)
      Image(this.icon)
        .width(30)
        .height(30)
        .align(Alignment.TopEnd)
      Image(this.icon)
        .width(30)
        .height(30)
        .align(Alignment.BottomStart)
      Image(this.icon)
        .width(30)
        .height(30)
        .align(Alignment.BottomEnd)

    }.width("100%")
    .height("100%")
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
HarmonyOS
2024-12-18 16:31:29
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

align设置容器元素绘制区域内的子元素的对齐方式。只在Stack、Button、Marquee、StepperItem、text、TextArea、TextInput、FolderStack中生效

使用弹性布局(Flex),参考代码:

Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { // 容器组件设置子元素居中
  Text('alignSelf Start').width('25%').height(80)
    .alignSelf(ItemAlign.Start)
    .backgroundColor(0xF5DEB3)
  Text('alignSelf Baseline')
    .alignSelf(ItemAlign.Baseline)
    .width('25%')
    .height(80)
    .backgroundColor(0xD2B48C)
  Text('alignSelf Baseline').width('25%').height(100)
    .backgroundColor(0xF5DEB3)
    .alignSelf(ItemAlign.Baseline)
  Text('no alignSelf').width('25%').height(100)
    .backgroundColor(0xD2B48C)
  Text('no alignSelf').width('25%').height(100)
    .backgroundColor(0xF5DEB3)

}.width('90%').height(220).backgroundColor(0xAFEEEE)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-layout-development-flex-layout-V5

分享
微博
QQ
微信
回复
2024-12-18 18:41:18


相关问题
HarmonyOS stack设置圆角生效
664浏览 • 1回复 待解决
HarmonyOS Text设置align居中
881浏览 • 1回复 待解决
HarmonyOS worker子线程在har包生效
399浏览 • 1回复 待解决
HarmonyOS expandSafeArea生效
1024浏览 • 1回复 待解决
HarmonyOS margin生效
1142浏览 • 1回复 待解决
HarmonyOS targetSpace生效问题
566浏览 • 1回复 待解决
HarmonyOS @Observed生效问题
1253浏览 • 1回复 待解决
HarmonyOS margin生效问题
735浏览 • 1回复 待解决
abiFilters配置生效
995浏览 • 1回复 待解决
HarmonyOS 单例模式生效
554浏览 • 1回复 待解决
HarmonyOS hitTestBehavior.block生效
921浏览 • 1回复 待解决
HarmonyOS Panel 设置 borderRadius 生效
1462浏览 • 1回复 待解决
HarmonyOS Web组件borderRadius生效
735浏览 • 1回复 待解决
HarmonyOS Span内边距生效
429浏览 • 1回复 待解决
HarmonyOS photoViewPicker智能推荐生效
946浏览 • 1回复 待解决
HarmonyOS 关于onKeyEvent生效问题
1039浏览 • 1回复 待解决
容器组件onVisibleAreaChange生效
2416浏览 • 1回复 待解决
ConstraintSize尺寸设置生效
2870浏览 • 1回复 待解决