在我的jetpack撰写中,我使用的是撰写1.1.1。我不能更新到最新版本。我想要像solution这样的东西。我的weight修饰符出错了。有人能指点我如何在weight中获得Row修饰符吗?
implementation "androidx.compose.runtime:runtime:$compose_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.compose.foundation:foundation-layout:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
androidTestImplementation "androidx.compose.ui:ui-test:$compose_version"
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
implementation "androidx.activity:activity-compose:$compose_version"Row.kt
Column {
Row(
modifier = Modifier.weight(1f, false)
) {
//...
}
}

误差
Expression 'weight' cannot be invoked as a function. The function 'invoke()' is not found非常感谢
更新
我在这里加了我的全部代码请看一下..。
@Composable
fun Input(optionData: OptionData) {
Column(
modifier = Modifier
.fillMaxSize()
) {
Item(optionData)
}
}
@Composable
fun Item(optionData: OptionData) {
/// more item of compose i.e. Text, Textfield
Submit()
}
@Composable
fun Submit() {
Row(
modifier = Modifier.weight(1f, false)
) {
//...
}
}更新2
在尝试@Thracian解决方案之后,它解决了weight的问题,但我的观点不会落空。
@Composable
fun Submit() {
Column {
OnSubmit {
PrimaryMaterialButton(text = stringResource(id = R.string.submit)) {
}
}
}
}
@Composable
fun ColumnScope.OnSubmit(content: @Composable () -> Unit) {
Row(
modifier = Modifier.weight(1f, false)
) {
content()
}
}发布于 2022-08-08 08:36:26
@Composable
fun Submit() {
Row(
modifier = Modifier.weight(1f, false)
) {
//...
}
}为了使这段代码能够从Modifier.weight()访问Column,它应该将接收方设置为ColumnScope。有些修饰符是用作用域创建的,因此它们仅在该作用域中可用,例如Modifier.weight用于行或列或Modifier.matchParentSize用于Box。
@Composable
fun ColumnScope.Submit() {
Row(
modifier = Modifier.weight(1f, false)
) {
//...
}
}
// Allowed
Column {
Submit()
}
//Not Allowed
Row() {
Submit()
}https://stackoverflow.com/questions/73271265
复制相似问题