Roar Gronmo
12/13/2019, 11:08 AMColumn
, Row
, modifier=
and Gravity
Do anyone have reasonable (sane) explanation on how I can achieve following tricky thing (see picture).
Here's the code where this layout is built, I want the "5 Center End me!" to be centered vertically (up-down) (as shown), but I can't find any reasonable way to do it in dev03, this was achievable in dev02...
@Composable
fun CardGravityTest()
{
Card(
modifier = Spacing(all = 4.dp),
color = Color.LightGray,
shape = RoundedCornerShape(
5.dp
)
){
Column {
Row {
Surface(color = Color.Red,
modifier = Spacing(all = 4.dp)) {
Text(text = "1 XX")
}
Column(modifier = Flexible(1f) wraps Expanded wraps Spacing(4.dp)){
Surface(color = Color.Green){
Text(text="2 Flexible wraps Expanded(1f) wraps Spacing(4.dp) x x xx xxx xxxx x xx xxx x xxx")
}
Surface(color = Color.Magenta){
Text(text = "3 Second line xxxxx xxx xx xxxxx xxxx")
}
}
Column() {
Surface(color = Color.DarkGray) {
Text(text = "4 Column: OK High on top!")
}
Surface(color = Color.Yellow,
modifier = Gravity.End){
Text(text = "5 Center End me!",
modifier = Gravity.End)
}
}
}
Divider()
Row (modifier = Spacing(top = 4.dp)){
Column (modifier = Flexible(1f) wraps Expanded){
Surface(color = Color.Blue, modifier = Gravity.Start) {
Text(text = "6 Row spacing top, Column Flexible(1f) wraps Expanded, Surface gravity start")
}
}
Column(modifier = Flexible(1f) wraps Expanded){
Surface(color = Color.Cyan, modifier = Gravity.End) {
Text(text = "7 Column Flexible wraps Expanded, Surface gravity end, " +
"paragraphstyle TextAlign.end ", paragraphStyle = ParagraphStyle(textAlign = TextAlign.End))
}
}
}
Row {
Surface(modifier = Spacing(all = 4.dp), color = Color.White) {
Text(text = "8 on Row")
}
Surface(modifier = Spacing(all = 4.dp), color = Color.Green)
{
Text(text = "9 on Row")
}
Column(modifier = Gravity.Center wraps Flexible(1f)){
Surface(color = Color.Red) {
Text(text = "10 col center flex, line 1")
}
Surface(color = Color.DarkGray)
{
Text(text = "11 line 2 xxxxxx")
}
}
Column(modifier = Gravity.Center wraps Expanded) {
Surface(color = Color.Magenta, modifier = Gravity.End) {
Text(text = "12 col cnt mod end")
}
}
}
}
}
}
Mihai Popa
12/13/2019, 3:19 PMGravity.End wraps Align.CenterVertically
modifier to the Surface of 5. This will make sure the Text is centered vertically in the remaining space after 4.Mihai Popa
12/13/2019, 3:21 PMMihai Popa
12/13/2019, 3:22 PMMihai Popa
12/13/2019, 3:25 PMRoar Gronmo
12/13/2019, 3:33 PMRoar Gronmo
12/13/2019, 9:56 PMmodifier=Gravity.End wraps Align.CenterVertically
. It redlines CenterVertically
, is this dev04 ?, or do I miss a dependency ?
Code below is the upper part (above Divider()
) justified to the suggestions you have.
fun CardGravityTest2()
{
Card(
modifier = Spacing(all = 4.dp),
color = Color.LightGray,
shape = RoundedCornerShape(
size = 5.dp
)
){
Column {
MaxIntrinsicHeight {
Row {
Surface(
color = Color.Red,
modifier = Spacing(all = 4.dp)
) {
Text(text = "1 Surface")
}
Column(
modifier = Flexible(
flex = 1f
) wraps Spacing(
all = 4.dp
)
) {
Surface(
color = Color.Green
) {
Text(text = "2 Column mod Flexible wraps Spacing," +
"Surface no mod ")
}
Surface(
color = Color.Magenta
){
Text(text = "3 Surface no mod ")
}
}
Column (modifier = ExpandedHeight) {
Surface(
modifier = Gravity.End,
color = Color.DarkGray
){
Text(text = "4. Col no mod, Srf Gr.end")
}
Surface(
modifier = Gravity.End wraps Align.CenterVertically,
color = Color.Yellow
){
Text(text = "5. Srf Gr. end, Center vert ? ")
}
}
}
}
}
}
}
(Tried to add a screenshot, it seems to have disappeared... sorry about that)Mihai Popa
12/13/2019, 10:00 PMMihai Popa
12/13/2019, 10:04 PMContainer
:
Container(Gravity.End wraps ExpandedHeight) {
Surface(color = Color.Yellow){
Text(text = "5 Center End me!")
}
}
Roar Gronmo
12/13/2019, 10:17 PM