这里有搞鸿蒙开发的兄弟吗?遇到一个布局问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
chillwind
V2EX    Android

这里有搞鸿蒙开发的兄弟吗?遇到一个布局问题

  •  
  •   chillwind 244 天前 5153 次点击
    这是一个创建于 244 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这里有搞鸿蒙开发的兄弟吗?今天遇到一个问题,搞了半天也没搞定。需求很简单就是让左边的竖线跟随整个 Row 的高度变化,整个 Row 的高度不定,后面的文本可能会换行。 Row() { // Vertical line decoration Row() .width(3) .height('100%') .backgroundColor('#DDDDDD')

     Column() { Row() { Text("Test1111") .fontSize(14) .fontWeight(FontWeight.Lighter) .fontStyle(FontStyle.Italic) .foregroundColor('#DDDDDD') .flexGrow(1) Button() { Text("button") .width(30) .height(30) } .width(30) .height(30) .backgroundColor(Color.Transparent) .foregroundColor('#DDDDDD') } .width('100%') .alignItems(VerticalAlign.Top) Text("long text long text long text long text long text ") .fontSize(14) .fontWeight(FontWeight.Lighter) .foregroundColor('#DDDDDD') .width('100%') .margin({ top: 2 }) } .margin({ left: 7 }) .layoutWeight(1) } .alignItems(VerticalAlign.Top) .width('100%') .margin({ top: 10 }) 
    20 条回复    2025-02-10 08:43:16 +08:00
    Ao04Ip922e2kXx7H
        1
    Ao04Ip922e2kXx7H  
       244 天前
    试试下面的

    ```
    @Component
    export struct DecoratedRow {
    build() {
    Row() {
    // Left decorative line that will stretch full height
    Row() {
    Row()
    .width(3)
    .backgroundColor('#DDDDDD')
    .height('100%')
    }
    .height('100%')
    .margin({ right: 4 })

    // Main content column
    Column() {
    Row() {
    Text("Test1111")
    .fontSize(14)
    .fontWeight(FontWeight.Lighter)
    .fontStyle(FontStyle.Italic)
    .foregroundColor('#DDDDDD')
    .flexGrow(1)

    Button() {
    Text("button")
    .width(30)
    .height(30)
    }
    .width(30)
    .height(30)
    .backgroundColor(Color.Transparent)
    .foregroundColor('#DDDDDD')
    }
    .width('100%')
    .alignItems(VerticalAlign.Top)

    Text("long text long text long text long text long text ")
    .fontSize(14)
    .fontWeight(FontWeight.Lighter)
    .foregroundColor('#DDDDDD')
    .width('100%')
    .margin({ top: 2 })
    }
    .margin({ left: 7 })
    .layoutWeight(1)
    }
    .alignItems(VerticalAlign.Top)
    .width('100%')
    .margin({ top: 10 })
    }
    }
    ```
    chillwind
        2
    chillwind  
    OP
       244 天前
    不行,只要高度设置了.height('100%'),这个 Row 就会占据整个屏幕剩余的区域
    lulaolu
        3
    lulaolu  
       244 天前
    heyjei
        4
    heyjei  
       244 天前
    这布局的代码风格,不看晕过去吗
    Helsing
        5
    Helsing  
       244 天前 via iPhone
    Compose 有固有特性测量,可以找找 Ark UI 有没有
    lisongeee
        6
    lisongeee  
       244 天前
    如果是 compose 就很简单,父布局设置 .height(IntrinsicSize.Min),子布局 .fillMaxHeight() 就完了
    Yuanlaoer
        7
    Yuanlaoer  
       244 天前
    这玩意儿的风格,之前除了 SwiftUI ,还有哪个语言或者框架用么?
    ZGame
        8
    ZGame  
       244 天前
    @Yuanlaoer flutter ,
    qwwuyu
        9
    qwwuyu  
       244 天前
    RelativeContainer() {
    Column() {
    Row() {
    Text("Test1111")
    .fontSize(14)
    .fontWeight(FontWeight.Lighter)
    .fontStyle(FontStyle.Italic)
    .foregroundColor('#DDDDDD')
    .flexGrow(1)
    Button() {
    Text("button")
    .width(30)
    .height(30)
    }
    .width(30)
    .height(30)
    .backgroundColor(Color.Transparent)
    .foregroundColor('#DDDDDD')
    }
    .width('100%')
    .alignItems(VerticalAlign.Top)

    Text("long text long text long text long text long text long text long text long text long text long text")
    .fontSize(14)
    .fontWeight(FontWeight.Lighter)
    .foregroundColor('#DDDDDD')
    .width('100%')
    .margin({ top: 2 })
    }
    .id('viewRight')
    .backgroundColor(0xff0000)
    .margin({ left: 10 })
    .alignRules({
    left: { anchor: '__container__', align: HorizontalAlign.Start },
    right: { anchor: '__container__', align: HorizontalAlign.End },
    })

    Row()
    .id('viewLine')
    .width(3)
    .backgroundColor(0x00ff00)
    .alignRules({
    top: { anchor: 'viewRight', align: VerticalAlign.Top },
    bottom: { anchor: 'viewRight', align: VerticalAlign.Bottom },
    })
    }
    .size({ width: '100%', height: 'auto' })
    .margin({ top: 10 })
    .backgroundColor(0x0000ff)

    //RelativeContainer 可以做到,但是稍微用错容易出不明所以的 BUG
    cadillac
        10
    cadillac  
       243 天前
    现在大模型对鸿蒙的 ArkUI 支持的怎么样了
    iOCZS
        11
    iOCZS  
       243 天前
    arkui 怎么配跟 SwiftUI 比较
    Yuanlaoer
        12
    Yuanlaoer  
       243 天前
    @ZGame 我只是说从 App 开发者的角度来看:
    对比了一下 flutter ,感觉区别还是挺大的。你去看看 SwiftUI 的代码,你再看看鸿蒙的 ArkUI ,你自己感受一下。
    Danmen123
        13
    Danmen123  
       243 天前
    @Yuanlaoer jetpack compose,android 主推的 UI 框架
    ZGame
        14
    ZGame  
       243 天前
    @Yuanlaoer #12 我只有简单用过 flutter 现在是在写 react 反正都是抄 react 的嘛
    Yuanlaoer
        15
    Yuanlaoer  
       243 天前
    @Danmen123 多谢,了解了。看 release 时间,差不多也是那段时期的
    Yuanlaoer
        16
    Yuanlaoer  
       243 天前
    @ZGame 您这个回复就跟吃意大利面一定要拌 37 号水泥差不多
    ZGame
        17
    ZGame  
       243 天前
    @Yuanlaoer #16 倒也不是吧 我记得原来写 flutter 的时候还是挺简单的。react 更函数式一点 这个看着像用了类的装饰器的那种链式写法。
    Yuanlaoer
        18
    Yuanlaoer  
       243 天前
    @ZGame 嗨,你要是从这个角度说,很多前端语言/框架都过不了几年就有这种情况。你这跑题跑的有点儿远了
    nicevar
        19
    nicevar  
       242 天前   1
    @Yuanlaoer 现在客户端开发基本上就是这个风格的,安卓的 Compose UI 基本上跟 ArkUI 一条裤子的,flutter 也大差不差。
    ZGame
        20
    ZGame  
       242 天前
    @Yuanlaoer #18 所以大同小异, 路径依赖就是 react->flutter->swiftUI,jetpack compose ,我猜测华为的不管是范式还是 ,Ui 渲染那块应该都有模仿 react flutter 的痕迹和实现吧。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3715 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 29ms UTC 00:51 PVG 08:51 LAX 17:51 JFK 20:51
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86