Open yznote opened 1 week ago
@lucdion @OhKanghoon Can you provide a good solution? Thank you
That is to say, CSS supports calc()
, such as width: calc (50% -5px)
May I ask if there are any related APIs in Flexlayout
@lucdion @OhKanghoon box ===> width:384 item【red、green、yellow、blue】 ===> width:(384-15*2-5)/2 ==174.5 item【systemOrange】===> width:177【174.5+2.5】 【red、green、yellow、blue】used for layout implementation 【systemOrange】used for comparison
complete code
rootView.flex.direction(.row).wrap(.wrap)
.justifyContent(.start).alignItems(.center).paddingHorizontal(15)
.rowGap(5).columnGap(5).grow(1).shrink(1).define { (flex) in
// 实际布局的四个item
flex.addItem().width(46%).height(25).backgroundColor(.red).grow(1)
flex.addItem().width(46%).height(25).backgroundColor(.green).grow(1)
flex.addItem().width(46%).height(25).backgroundColor(.yellow).grow(1)
flex.addItem().width(46%).height(25).backgroundColor(.blue).grow(1)
// 用于对比
flex.addItem().width(50%).height(25).backgroundColor(.systemOrange)
}
addSubview(rootView)
rootView.backgroundColor = .hex("#fff", 0.2)
The core is to set an approximate value for width
and then use grow
alignment.
It looks perfect, but I'm not sure if it's really used this way.
If it is a multi row layout, how to set the gap combination percentage Expectation: Two columns per row, for a total of two rows Actual: Only one column
Originally posted by @yznote in https://github.com/layoutBox/FlexLayout/issues/262#issuecomment-2477880327