I'm in the process of working through Android Compose Unit 1->Pathway 3 (Build a Basic Layout) "Practice: Compose Basics" Codelab, section 4. Compose quadrant, and I keep getting an error on play/build: Unresolved reference: weight when using only a Row layout block with Modifier.weight included. So I resorted to checking the Solution code for MainActivity.kt, which surrounded this Row block with a Column block, and this builds fine. This is fine for me in moving on, but, for the sake of learning, I'm just wondering why the surrounding Column block is necessary, primarily because many answers on stackO suggested that Modifier.weight is supported in a Row or Column layout block on its own. Does anyone know the distinction here?Here's my code (problematic functionality (ComposeRowWithWeightAndColumns) preceding the working functionality (ComposeColumnWithRowAndColumns)):
@Composablefun ComposeRowWithWeightAndColumns(modifier: Modifier = Modifier){ Row(Modifier.weight(1f)) { // ********** error pops here *************** Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { ComposeCard("Android0", "Body0", 0) ComposeCard("Android2", "Body2", 2) } Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { ComposeCard("Android1", "Body randomX", 1) ComposeCard("Android3", "Body random", 3) } }}@Composablefun ComposeColumnWithRowAndColumns(modifier: Modifier = Modifier){ Column(Modifier.fillMaxWidth()) { Row(Modifier.weight(1f)) { // ********** no error here *************** Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { ComposeCard("Android0", "Body0", 0) ComposeCard("Android2", "Body2", 2) } Column( horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { ComposeCard("Android1", "Body randomX", 1) ComposeCard("Android3", "Body random", 3) } } }}
FYI: I'm running Android Studio Hedgehog | version 2023.1.1 Patch 1 on a Mac running Monterey Version 12.7.2