Sterling Albury
05/18/2022, 7:52 PMRow(
modifier = Modifier
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
leftHandContent(
Modifier
.wrapContentWidth()
)
Text(
modifier = Modifier
.wrapContentWidth()
.align(CenterVertically)
.weight(1F, fill = true),
text = appBarTitle,
color = topBarPrimaryColor,
fontWeight = FontWeight.Bold,
fontSize = 22.sp,
textAlign = TextAlign.Center
)
rightHandContent(
Modifier
.wrapContentWidth()
)
}
I would like the Text to be in the center of the bar but also be constrained by the left and right hand content. If one of the content items is missing, then I'd still like the text to be centered in the row. Considering a couple of options here. I briefly tried using a Box and using the align modifiers for the content items, but the text wasn't getting constrained like i wanted and got some overlap with the contents. trying to not use the constraint layout. Was looking at a custom layout and using some vertical baselines but not very familiar with using those objects. Any thoughts?ste
05/18/2022, 7:55 PMSpacer
with the same size of the item at the rightSterling Albury
05/18/2022, 7:58 PMste
05/18/2022, 8:01 PMConstraintLayout
is the waySterling Albury
05/18/2022, 8:06 PMChris Sinco [G]
05/18/2022, 9:59 PMOleksandr Balan
05/18/2022, 10:00 PMLayout
. You can take m3 implementation of TopAppBarLayout as an inspiration:
https://androidx.tech/artifacts/compose.material3/material3/1.0.0-alpha01-source/androidx/compose/material3/AppBar.kt.html
See how it measures and places title when titleHorizontalArrangement
is Arrangement.Center
.
Basically you should measure your “left hand” and “right hand” first and then constraint the width for title accordingly.Sterling Albury
05/18/2022, 10:06 PMSterling Albury
05/18/2022, 10:10 PMOleksandr Balan
05/18/2022, 10:22 PMBoxWithConstraints
uses SubcomposeLayout
which is more powerful, but less efficient than Layout