HarmonyOS 如何实现类似match_parent的效果

以下例子,stack通过alignSelf(ItemAlign.Stretch)跟兄弟组件最大宽度保持一致,接下来如何实现stack内子组件宽度充满父容器的效果?

@Entry 
@Component 
export struct DD { 
  build() { 
    Column() { 
      Text('ttt') 
        .alignSelf(ItemAlign.Stretch) 
        .backgroundColor(Color.Gray) 
      Stack() { 
        Text('1111') 
        // .width('100%') 
      } 
      .alignSelf(ItemAlign.Stretch) 
      .backgroundColor(Color.Yellow) 
      Text('ttttt') 
        .width(100) 
        .backgroundColor(Color.Pink) 
    } 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.

HarmonyOS 如何实现类似match_parent的效果-鸿蒙开发者社区

HarmonyOS
2024-09-03 11:59:48
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

可以使用constraintSize属性来限制子组件的宽高,具体实现参考如下链接:constraintSize

分享
微博
QQ
微信
回复
2024-09-03 16:50:05
相关问题
如何实现类似keyframes效果
2357浏览 • 1回复 待解决
HarmonyOS 怎么实现类似SnackBar效果
626浏览 • 1回复 待解决
HarmonyOS 类似翻页效果实现
932浏览 • 1回复 待解决