+ 2

What is the use of weight modifier in Jetpack Compose?

I've started learning Android few days ago, and I got a practice problems in layout to divide the screen in 4 parts, and in single part there must be text in center, I was trying many stuff but didn't get the result, I saw that in webpage there was a reference of Modifier.weight but I didn't get it Link: https://developer.android.com/codelabs/basic-android-kotlin-compose-composables-practice-problems "Compose Quadrant" section , I know that there are two rows and two columns to make and each row has 2 column of text, but how to fill the size of screen

30th Mar 2024, 4:00 PM
Aishwaray Tiwary
Aishwaray Tiwary - avatar
1 Odpowiedź
+ 2
In Jetpack Compose, Modifier.weight is used to distribute available space among composables within a layout. It is commonly used in combination with Column or Row layouts to define how much space each child should occupy relative to others. In the context of the problem you're trying to solve, you want to divide the screen into four parts, where each part contains text centered within it. To achieve this, you can use a Colmn containing two Row composables. Each Row will represent one row of your screen, and each Row will contain two Text composables representing the text in the center of each quadrant. Here is how you can get this using Modifier.weight https://www.sololearn.com/en/compiler-playground/cF2FQ3QmUIGn
9th Apr 2024, 6:57 AM
Jishnu Satheesh Pulickal