@@ -3,13 +3,23 @@ package com.lahsuak.apps.jetpackcomposebasic
3
3
import android.os.Bundle
4
4
import androidx.activity.ComponentActivity
5
5
import androidx.activity.compose.setContent
6
+ import androidx.compose.foundation.background
7
+ import androidx.compose.foundation.layout.Box
6
8
import androidx.compose.foundation.layout.fillMaxSize
9
+ import androidx.compose.foundation.shape.CircleShape
7
10
import androidx.compose.material3.MaterialTheme
8
11
import androidx.compose.material3.Surface
9
- import androidx.compose.material3.Text
10
12
import androidx.compose.runtime.Composable
11
13
import 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
12
17
import 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
13
23
import com.lahsuak.apps.jetpackcomposebasic.ui.theme.JetPackComposeBasicTheme
14
24
15
25
class MainActivity : ComponentActivity () {
@@ -22,29 +32,70 @@ class MainActivity : ComponentActivity() {
22
32
modifier = Modifier .fillMaxSize(),
23
33
color = MaterialTheme .colorScheme.background
24
34
) {
25
- Greeting ( " Android " )
35
+ IndianFlagScreen ( )
26
36
}
27
37
}
28
38
}
29
39
}
30
40
}
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
+
39
42
@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
+ }
42
93
}
43
94
44
95
@Preview(showBackground = true )
45
96
@Composable
46
97
fun DefaultPreview () {
47
98
JetPackComposeBasicTheme {
48
- Greeting ( " Android " )
99
+ IndianFlagScreen ( )
49
100
}
50
101
}
0 commit comments