I have a Box
in my app with a bunch of children:
Box(modifier = Modifier.fillMaxSize()) {
Text("a")
Text("b")
}
I want the text to appear aligned to the top at 20% distance from the start. How do I achieve that?
CodePudding user response:
To solve this you need two parts:
There're two ways to layout
Box
content:contentAlignment
will apply alignment for all children, andModifier.align
, which can be applied for a specific child.Usually you can use
Modifier.padding
in such cases, but not in case when you need relative size. The easiest way to take part of parent size is usingModifier.fillMax...
, modifier, in this caseModifier.fillMaxWidth(0.2f)
can be applied to aSpacer
, placed in aRow
with your element.
Box(modifier = Modifier.fillMaxSize()) {
Row(
Modifier
.align(Alignment.TopStart)
) {
Spacer(Modifier.fillMaxWidth(0.2f))
Text("a")
}
}
CodePudding user response:
Use the offset
/absoluteOffset
modifiers along with BoxWithConstraints
.