gpt4 book ai didi

android - Jetpack 组成 : how to force a dropdownmenu to be anchored underneath its parent?

转载 作者:行者123 更新时间:2023-12-05 06:02:18 26 4
gpt4 key购买 nike

我目前正在使用 dropdownmenu 在我的应用程序中选择众多选项之一。问题是,一旦其中包含许多元素,下拉菜单就会扩展到最初锚定的位置之上(见附图)。我怎样才能像第一张图片那样强制下拉菜单固定在按钮的底部?谢谢!

what i want (only works with few items in the list)

the problem (occurs when there is lots of items in the list)

编辑:这里是相关代码:

Box(modifier = Modifier.fillMaxWidth()) { // box for dropdown menu
Button(
modifier = Modifier.fillMaxWidth(),
onClick = { showCategories = true }
) {
Icon(Icons.Default.Favorite, null)
Text("${currentCategory.name}")
Icon(
painter = painterResource(id = R.drawable.ic_baseline_expand_more_24),
contentDescription = "expand more"
)
}
DropdownMenu(
expanded = showCategories,
onDismissRequest = {
showCategories = false
}
) {
categories.forEach {
DropdownMenuItem(
onClick = {
onCategoryChangeRequest(it)
showCategories = false
}
) {
Text(it.name)
}
}
}
}

最佳答案

您可以为您的 DropdownMenu 分配最大尺寸。

DropdownMenu(
modifier = Modifier.requiredSizeIn(maxHeight = 200.dp),
...
)

它对我有用...

enter image description here

关于android - Jetpack 组成 : how to force a dropdownmenu to be anchored underneath its parent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66965883/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com