英文:
Unable to stack row on top of row using jetpack compose
问题
以下是翻译好的部分:
我目前有以下代码:
编辑 1:
@Composable
fun CustomerProfile(
customerProfileViewModel: CustomerProfileViewModel = viewModel()
) {
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
}
) { _ ->
Row(
modifier = Modifier.fillMaxSize()
) {
Row {
HeaderPlate(
scope = scope,
snackbarState = snackbarHostState,
firstName = customerProfileViewModel.getStateValue().customer.firstName,
lastName = customerProfileViewModel.getStateValue().customer.lastName,
)
CustomerDetailsList(initialiseCustomerDetailsList(customerProfileViewModel))
}
}
}
}
这段代码创建了以下视图:
然而,我想要的是将灰色行放在蓝色标题下面。我对Compose还有点不熟悉,所以希望能得到一些帮助!
谢谢!
编辑 1:
我已经按照你的建议更改了代码,现在我得到了以下结果:
如你所见,列表完全消失了。
英文:
I have the following code currently:
Edit 1:
@Composable
fun CustomerProfile(
customerProfileViewModel: CustomerProfileViewModel = viewModel()
) {
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
}
) { _ ->
Row(
modifier = Modifier.fillMaxSize()
) {
Row {
HeaderPlate(
scope = scope,
snackbarState = snackbarHostState,
firstName = customerProfileViewModel.getStateValue().customer.firstName,
lastName = customerProfileViewModel.getStateValue().customer.lastName,
)
CustomerDetailsList(initialiseCustomerDetailsList(customerProfileViewModel))
}
}
}
}
This creates the following view:
However, what I want is to have the grey rows below the blue header. I'm a little new to compose still so any help would be appreciated!
Thanks!
Edit 1:
I've changed the code to what you've suggested and now I get the following:
As you can see, the list has entirely disappeared.
答案1
得分: 0
你应该使用Column
而不是Box
:
@Composable
fun CustomerProfile(
customerProfileViewModel: CustomerProfileViewModel = viewModel()
) {
val customerDetailsList: List<CustomerDetails> = initialiseCustomerDetailsList(viewModel = customerProfileViewModel)
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
}
) { it ->
// ... 在这里使用 Column ...
Column(
modifier = Modifier.fillMaxSize()
) {
HeaderPlate(
scope = scope,
snackbarState = snackbarHostState,
firstName = customerProfileViewModel.getStateValue().customer.firstName,
lastName = customerProfileViewModel.getStateValue().customer.lastName,
)
LazyColumn {
items(count = customerDetailsList.size) { index ->
val customer = customerDetailsList[index]
CustomerDetailsCard(
icon = customer.icon,
title = customer.title,
value = customer.value,
)
}
}
}
}
}
英文:
You should use Column
instead of Box
:
@Composable
fun CustomerProfile(
customerProfileViewModel: CustomerProfileViewModel = viewModel()
) {
val customerDetailsList: List<CustomerDetails> = initialiseCustomerDetailsList(viewModel = customerProfileViewModel)
val snackbarHostState = remember { SnackbarHostState() }
val scope = rememberCoroutineScope()
Scaffold(
snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
}
) { it ->
// ... Use Column Here ...
Column(
modifier = Modifier.fillMaxSize()
) {
HeaderPlate(
scope = scope,
snackbarState = snackbarHostState,
firstName = customerProfileViewModel.getStateValue().customer.firstName,
lastName = customerProfileViewModel.getStateValue().customer.lastName,
)
LazyColumn {
items(count = customerDetailsList.size) {index ->
val customer = customerDetailsList[index]
CustomerDetailsCard(
icon = customer.icon,
title = customer.title,
value = customer.value,
)
}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论