我试着把卡片重叠在一起。有两张卡,卡1和卡2。因此,我想将它们彼此重叠,这样用户就知道Card2在Card1下方,因此我想将Card2倾斜到两侧。我写了下面的代码,但它只显示Card2。MainActivity.kt
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
OverlappingCardsTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
OverlappingCards()
}
}
}
}
}
@Composable
fun OverlappingCards(){
Box(modifier = Modifier.fillMaxSize()){
Card(
modifier = Modifier
.size(200.dp, 300.dp)
.offset(40.dp, 40.dp),
elevation = CardDefaults.cardElevation(
defaultElevation = 10.dp)
) {
// Content of the first card
Text(text = "Hello Card1")
}
Card(
modifier = Modifier
.size(200.dp, 300.dp)
.offset(40.dp, 40.dp),
elevation = CardDefaults.cardElevation(
defaultElevation = 10.dp)
) {
// Content of the first card
Text(text = "Hello Card2")
}
}
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
OverlappingCardsTheme {
}
}
1条答案
按热度按时间ldxq2e6h1#
将旋转修改器添加到您的一张牌修改器:
我也会稍微增加在顶部卡的海拔,使它更容易脱颖而出,但取决于您的用户界面