android - Jetpack compose 中 Unresolved 修改器方法引用

标签 android android-jetpack-compose

我正在学习 Jetpack Compose,我正在尝试使用 Modifier 方法高度和填充来自定义图像的显示。但是我收到了问题消息“ Unresolved reference :高度”和“ Unresolved reference :填充”。

@Preview
@Composable
fun imageDisplay() {
    Column(
        modifier = Modifier.padding(16.dp)
    ) {
        Image(
            painter = painterResource(R.drawable.photo_1505740420928_5e560c06d30e),
            contentDescription = null,
            modifier = Modifier
                .height(180.dp)
                .fillMaxWidth()
                .clip(shape = RoundedCornerShape(4.dp)),
            contentScale = ContentScale.Crop

        )

    }

}
padding and height methods highlighted in red
我错过了什么吗?

最佳答案

一切看起来都很好。确保您使用的是最新版本的 Android Studio、gradle 和 compose 版本。

  • Android Studio 海豚 | 2021.3.1 金丝雀5
  • 撰写版本 1.2.0-alpha05
  • implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.material:material-ripple:$compose_version"
    
    最后,检查您是否导入了正确的 Modifier类(class)。
    您必须使用 androidx.compose.ui 中的那个包裹。

    关于android - Jetpack compose 中 Unresolved 修改器方法引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67264430/

    相关文章:

    android - Jetpack UI 组合。如何创建 FloatingActionButton?

    java - 如何在事件调用后200ms触发方法?

    android - 静态队列与共享首选项

    Android Studio 如何修复无法创建类文件错误?

    Java:OpenGl ES 2.0 着色器灯

    android - Jetpack 撰写 : DrawBehind not same height as Button Background

    java - 数学公式格式没有出现在android mathView中

    android - 如何在 Jetpack Compose 中填充矢量图像的背景?

    android - 忽略 Jetpack Compose Card 上的单击,但在包含的布局中捕获它

    android - android jetpack compose中的 "remember"和 "mutableState"有什么区别?