var isVisible by remember { mutableStateOf(true) }
AnimatedVisibility(visible = isVisible) {
Text("Hello, Jetpack Compose!")
}
Button(onClick = { isVisible = !isVisible }) {
Text("Toggle Visibility")
}
val alpha by animateFloatAsState(targetValue = if (isVisible) 1f else 0f)
Box(modifier = Modifier.alpha(alpha)) {
Text("Fading Text")
}
var expanded by remember { mutableStateOf(false) }
Box {
Button(onClick = { expanded = true }) {
Text("Show Menu")
}
DropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false }
) {
DropdownMenuItem(onClick = { /* Handle click */ }) {
Text("Option 1")
}
DropdownMenuItem(onClick = { /* Handle click */ }) {
Text("Option 2")
}
}
}
@Serializable
data class User(val name: String, val age: Int)
val json = Json { prettyPrint = true }
val user = User("John", 25)
val jsonString = json.encodeToString(user)
val userData = json.decodeFromString<User>(jsonString)
Text(
"Text with baseline padding",
modifier = Modifier.paddingFromBaseline(top = 32.dp)
)
Box(
modifier = Modifier
.fillMaxSize()
.foldablePane(FoldOrientation.Vertical)
) {
Text("Content adapts to fold orientation")
}
var expanded by remember { mutableStateOf(false) }
Box(
modifier = Modifier
.clickable { expanded = !expanded }
.animateContentSize()
.background(Color.Gray)
.padding(16.dp)
) {
Text("Click to expand", maxLines = if (expanded) Int.MAX_VALUE else 1)
}
val rotation by animateFloatAsState(targetValue = if (isRotated) 360f else 0f)
Box(
modifier = Modifier
.size(100.dp)
.graphicsLayer(rotationZ = rotation)
) {
Text("Rotating Box")
}
val lazyPagingItems = pager.collectAsLazyPagingItems()
LazyColumn {
items(lazyPagingItems) { item ->
Text("Item: ${item?.name}")
}
}
LazyColumn {
items(list) { item ->
Text("Item $item")
}
item {
Button(onClick = { loadMoreItems() }) {
Text("Load More")
}
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。