345.17K
Category: programmingprogramming

JetPack Compose

1.

JetPack Compose
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackCompose1Theme {
Text(text = "Hello ")
}
}
Hello
}}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackCompose1Theme {
Text(text = "Hello1")
Text(text = "Hello2 ")
}
}
Hello1 Hello2
}}
@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState:
Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackCompose1Theme {
Column {
Greeting("Android2")
Greeting("Android3")
}
}
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState:
Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackCompose1Theme {
Row{
Greeting("Android1")
Column {
Greeting("Android2")
Greeting("Android3")
}
}
}
Hello Android 1! Hello Android2!
Hello Android3!
Hello Android2!
Hello Android3!

2.

JetPack Compose
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackCompose1Theme {
Greeting("Android3")
}
}
}}
@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}
Hello Android3!
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState:
Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackCompose1Theme {
Column {
Greeting("Android2")
Greeting("Android3")
}
class MainActivity
: ComponentActivity() {
}
override fun onCreate(savedInstanceState:
Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackCompose1Theme {
Row{
Greeting("Android1")
Column {
Greeting("Android2")
Greeting("Android3")
}
}
}
Hello Android 1! Hello Android2!
Hello Android3!
Hello Android2!
Hello Android3!

3.

JetPack Compose
Row(modifier = Modifier.padding(all = 8.dp)) {
Image(
painter =
painterResource(androidx.leanback.R.drawable.lb_ic_play),
contentDescription = "Contact profile picture",
modifier = Modifier
// Set image size to 40 dp
.size(40.dp)
// Clip image to be shaped as a circle
.clip(CircleShape)
)
Column {
Greeting("Android2")
Greeting("Android3")
}
Hello Android2!
Hello Android3!

4.

JetPack Compose
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackCompose1Theme {
Surface(
//modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colors.secondaryVariant
){
Row(modifier = Modifier.padding(all = 8.dp)) {
Image(
painter =
painterResource(androidx.leanback.R.drawable.lb_ic_play),
contentDescription = "Contact profile picture",
modifier = Modifier
// Set image size to 40 dp
.size(40.dp)
// Clip image to be shaped as a circle
.clip(CircleShape)
)
Column {
Greeting("Android2")
Greeting("Android3")
}
}
Hello Android2!
Hello Android3!
@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}

5.

Переменные mutable
fun HelloContent() {
Column(modifier = Modifier.padding(16.dp)) {
var name by remember { mutableStateOf("") }
if (name.isNotEmpty()) {
Text(
text = "Hello, $name!",
modifier = Modifier.padding(bottom =
8.dp),
style = MaterialTheme.typography.h5
)
}
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Name") }
)
}

6.

Жесты

7.

Прокрутка

8.

Прокрутка
fun HelloContent() {
Column(
modifier = Modifier
.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
){
Column(
modifier = Modifier
.size(100.dp)
.verticalScroll(rememberScrollState()),
){
repeat(100) {
Text(text = "Item$it", modifier = Modifier.padding(2.dp))
}
}
}
a = listOf("aa", "bb", "ccc",",fgfhfh","dfgfdgfd")
setContent {
HelloContent(a)
}
fun HelloContent(a: List<String>) {

a.forEach { a->
Text(text = a, modifier =
Modifier.padding(2.dp))
}
English     Русский Rules