Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android jetpack compose – Why the Row in Card out of the scope of Card with fillMaxWidth()

Posted on November 11, 2022 By

Solution 1 :

Change the Column modifier to weight.

From,

modifier = Modifier.fillMaxWidth()

To

modifier = Modifier.weight(1F)

The fillMaxWidth modifier is used to make the Column as wide as possible. Whereas here the requirement is to fill as wide as possible leaving space for the Spacer and Switch. That is achieved by using the weight modifier.

Weight

The parent will divide the horizontal space remaining after measuring unweighted child elements and distribute it according to this weight.

FillMaxWidth

Have the content fill (possibly only partially) the Constraints.maxWidth of the incoming measurement constraints, by setting the minimum width and the maximum width to be equal to the maximum width multiplied by fraction.

Note that, by default, the fraction is 1, so the modifier will make the content fill the whole available width.

Reference

  • weight

  • fillMaxWidth

Problem :

My code:

@ExperimentalMaterial3Api
@Composable
fun Settings() {
    Card(modifier = Modifier
        .fillMaxWidth()
    ) {
        SettingItem(itemTitle = "Test Title", itemDescription = "Description")
    }
}

@ExperimentalMaterial3Api
@Composable
fun SettingItem(itemTitle: String, itemDescription: String) {
    Row(modifier = Modifier.padding(12.dp).fillMaxWidth()) {
        Column(modifier = Modifier.fillMaxWidth()) {
            Text(text = itemTitle, color = MaterialTheme.colorScheme.primary)
            Text(text = itemDescription, color = MaterialTheme.colorScheme.secondary)
        }
        Spacer(modifier = Modifier.size(width = 12.dp, height = 4.dp))
        Switch(checked = false, onCheckedChange = {})
    }
}

I want to put a Switch at the end of a SettingItem, so I set fillMaxWidth(). But the Switch shows out of the layout of Card.

Image

READ  [FIXED] android - How to scale the camera preview to any given dimensions or shapes in a translucent background using Jetpack Compose
Powered by Inline Related Posts
Android Tags:android-jetpack-compose, android-jetpack-compose-layout

Post navigation

Previous Post: [FIXED] Android ACTION_VIEW intent is not opening urls in non-browser apps like twitter and instagram
Next Post: [FIXED] android – Check if activity is active, and if active pass data from service to activity?

Related Posts

[FIXED] android – Unable to match parent the custom dialog’s width Android
[FIXED] android – Statement List Generator and Tester rejects its own generated content Android
[FIXED] Android Java: How to get component in a custom view? (Trying to access components via findByViewId and get null) Android
[FIXED] java – Firestore Query Problem: Where is I am mistaken? Android
[FIXED] java – click back twice to close app with toast in drawer layout Android
[FIXED] Android Platform (TV): How to run a process at some common level where other android apps can pass data to it Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is a good substitute for condensed milk?
  • ¿Como el cuerpo te avisa cuando te va a dar un infarto?
  • What is the luxury brand of Jaguar?
  • Who is Big poppa baseball player?
  • What material are foam runners?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme