@@ -3,13 +3,24 @@ 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.layout.padding
10
+ import androidx.compose.foundation.shape.CircleShape
7
11
import androidx.compose.material3.MaterialTheme
8
12
import androidx.compose.material3.Surface
9
- import androidx.compose.material3.Text
10
13
import androidx.compose.runtime.Composable
11
14
import androidx.compose.ui.Modifier
15
+ import androidx.compose.ui.draw.clip
16
+ import androidx.compose.ui.graphics.Color
17
+ import androidx.compose.ui.layout.layoutId
12
18
import androidx.compose.ui.tooling.preview.Preview
19
+ import androidx.compose.ui.unit.dp
20
+ import androidx.constraintlayout.compose.ChainStyle
21
+ import androidx.constraintlayout.compose.ConstraintLayout
22
+ import androidx.constraintlayout.compose.ConstraintSet
23
+ import androidx.constraintlayout.compose.Dimension
13
24
import com.lahsuak.apps.jetpackcomposebasic.ui.theme.JetPackComposeBasicTheme
14
25
15
26
class MainActivity : ComponentActivity () {
@@ -22,29 +33,70 @@ class MainActivity : ComponentActivity() {
22
33
modifier = Modifier .fillMaxSize(),
23
34
color = MaterialTheme .colorScheme.background
24
35
) {
25
- Greeting ( " Android " )
36
+ IndianFlagScreen ( )
26
37
}
27
38
}
28
39
}
29
40
}
30
41
}
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
- ***/
42
+
39
43
@Composable
40
- fun Greeting (name : String ) {
41
- Text (text = " Hello $name !" )
44
+ fun IndianFlagScreen () {
45
+ val constraints = ConstraintSet {
46
+ val orangeBox = createRefFor(" orangebox" )
47
+ val greenBox = createRefFor(" greenbox" )
48
+ val circle = createRefFor(" circle" )
49
+
50
+ constrain(orangeBox) {
51
+ top.linkTo(parent.top)
52
+ start.linkTo(parent.start)
53
+ end.linkTo(parent.end)
54
+ bottom.linkTo(circle.top)
55
+ width = Dimension .fillToConstraints
56
+ height = Dimension .value(260 .dp)
57
+ }
58
+ constrain(circle) {
59
+ top.linkTo(parent.top)
60
+ bottom.linkTo(parent.bottom)
61
+ start.linkTo(parent.start)
62
+ end.linkTo(parent.end)
63
+ width = Dimension .value(100 .dp)
64
+ height = Dimension .value(100 .dp)
65
+ }
66
+ constrain(greenBox) {
67
+ top.linkTo(circle.bottom)
68
+ bottom.linkTo(parent.bottom)
69
+ start.linkTo(parent.start)
70
+ end.linkTo(parent.end)
71
+ width = Dimension .fillToConstraints
72
+ height = Dimension .value(260 .dp)
73
+ }
74
+ createVerticalChain(orangeBox, circle, greenBox, chainStyle = ChainStyle .SpreadInside )
75
+ }
76
+ ConstraintLayout (constraints, modifier = Modifier .fillMaxSize()) {
77
+ Box (
78
+ modifier = Modifier
79
+ .background(Color (0xFFFB8C00 ))
80
+ .layoutId(" orangebox" )
81
+ )
82
+ Box (
83
+ modifier = Modifier
84
+ .clip(CircleShape )
85
+ .background(Color .Blue )
86
+ .layoutId(" circle" )
87
+ )
88
+ Box (
89
+ modifier = Modifier
90
+ .background(Color (0xFF2EB734 ))
91
+ .layoutId(" greenbox" )
92
+ )
93
+ }
42
94
}
43
95
44
96
@Preview(showBackground = true )
45
97
@Composable
46
98
fun DefaultPreview () {
47
99
JetPackComposeBasicTheme {
48
- Greeting ( " Android " )
100
+ IndianFlagScreen ( )
49
101
}
50
102
}
0 commit comments