Wieso ist bei Android Jetpack Compose beim Modifier (fillMaxSize() vs padding()) die Reihenfolge wichtig?

Hallo,

Wieso ist bei Android Jetpack Compose beim Modifier (fillMaxSize() vs padding()) die Reihenfolge wichtig?

Ich erhalte für die Modifier:

  • Modifier.fillMaxSize().padding(16.dp)
  • Modifier.padding(16.dp).fillMaxSize()

Nicht das selbe Ergebnis.

Zweiteres erzeugt ein Kleineres Composable -> aber da das eine Doch nach außen wirkt (fillMaxSize) und das andere nach Innen (padding), sollte es mmn nicht wichtig sein, in welcher Reihenfolge ich es definiere.

So wie bei HTML auch.

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
1 Answer
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Erzesel
6 months ago

In advance:

I am not a jetpack programmer and can only draw logical conclusions from the (fastly flying) documentation…

see Padding:

Jetpack Compose doesn’t have a modifier for margin. We should use the padding modifier for both padding and margin. (Depending on the position/order in a sequence of formattings.)

@Composable
fun TextWidthPadding() {
    Text(
        "Padding and margin!",
        Modifier.padding(32.dp) // Outer padding (margin)
            .background(color = Color.Green) //background color
            .padding(16.dp) // Inner padding
    )
}

in your case this would mean that a pudding() before Fillmaxsize() as Margin act. Padding() After Fillmaxsize() as Padding

***Declaration under reservation that it is not my area of expertise! 😇