@@ -3,13 +3,23 @@ package com.lahsuak.apps.jetpackcomposebasic
33import android.os.Bundle
44import androidx.activity.ComponentActivity
55import androidx.activity.compose.setContent
6+ import androidx.compose.foundation.background
7+ import androidx.compose.foundation.layout.Box
68import androidx.compose.foundation.layout.fillMaxSize
9+ import androidx.compose.foundation.shape.CircleShape
710import androidx.compose.material3.MaterialTheme
811import androidx.compose.material3.Surface
9- import androidx.compose.material3.Text
1012import androidx.compose.runtime.Composable
1113import androidx.compose.ui.Modifier
14+ import androidx.compose.ui.draw.clip
15+ import androidx.compose.ui.graphics.Color
16+ import androidx.compose.ui.layout.layoutId
1217import androidx.compose.ui.tooling.preview.Preview
18+ import androidx.compose.ui.unit.dp
19+ import androidx.constraintlayout.compose.ChainStyle
20+ import androidx.constraintlayout.compose.ConstraintLayout
21+ import androidx.constraintlayout.compose.ConstraintSet
22+ import androidx.constraintlayout.compose.Dimension
1323import com.lahsuak.apps.jetpackcomposebasic.ui.theme.JetPackComposeBasicTheme
1424
1525class MainActivity : ComponentActivity () {
@@ -22,29 +32,70 @@ class MainActivity : ComponentActivity() {
2232 modifier = Modifier .fillMaxSize(),
2333 color = MaterialTheme .colorScheme.background
2434 ) {
25- Greeting ( " Android " )
35+ IndianFlagScreen ( )
2636 }
2737 }
2838 }
2939 }
3040}
31- /* **
32- Composable functions :
33- A composable function is a regular function annotated with @Composable.
34- This enables your function to call other @Composable functions within it.
35- You can see how the Greeting function is marked as @Composable.
36- This function will produce a piece of UI hierarchy displaying the given input,
37- String. Text is a composable function provided by the library.
38- ***/
41+
3942@Composable
40- fun Greeting (name : String ) {
41- Text (text = " Hello $name !" )
43+ fun IndianFlagScreen () {
44+ val constraints = ConstraintSet {
45+ val orangeBox = createRefFor(" orangebox" )
46+ val greenBox = createRefFor(" greenbox" )
47+ val circle = createRefFor(" circle" )
48+
49+ constrain(orangeBox) {
50+ top.linkTo(parent.top)
51+ start.linkTo(parent.start)
52+ end.linkTo(parent.end)
53+ bottom.linkTo(circle.top)
54+ width = Dimension .fillToConstraints
55+ height = Dimension .value(260 .dp)
56+ }
57+ constrain(circle) {
58+ top.linkTo(parent.top)
59+ bottom.linkTo(parent.bottom)
60+ start.linkTo(parent.start)
61+ end.linkTo(parent.end)
62+ width = Dimension .value(100 .dp)
63+ height = Dimension .value(100 .dp)
64+ }
65+ constrain(greenBox) {
66+ top.linkTo(circle.bottom)
67+ bottom.linkTo(parent.bottom)
68+ start.linkTo(parent.start)
69+ end.linkTo(parent.end)
70+ width = Dimension .fillToConstraints
71+ height = Dimension .value(260 .dp)
72+ }
73+ createVerticalChain(orangeBox, circle, greenBox, chainStyle = ChainStyle .SpreadInside )
74+ }
75+ ConstraintLayout (constraints, modifier = Modifier .background(Color .White ).fillMaxSize()) {
76+ Box (
77+ modifier = Modifier
78+ .background(Color (0xFFFB8C00 ))
79+ .layoutId(" orangebox" )
80+ )
81+ Box (
82+ modifier = Modifier
83+ .clip(CircleShape )
84+ .background(Color .Blue )
85+ .layoutId(" circle" )
86+ )
87+ Box (
88+ modifier = Modifier
89+ .background(Color (0xFF2EB734 ))
90+ .layoutId(" greenbox" )
91+ )
92+ }
4293}
4394
4495@Preview(showBackground = true )
4596@Composable
4697fun DefaultPreview () {
4798 JetPackComposeBasicTheme {
48- Greeting ( " Android " )
99+ IndianFlagScreen ( )
49100 }
50101}
0 commit comments