Jetpack compose 中的 Modifier.fillMaxSize 错误未解决的参考错误

问题描述 投票:0回答:2

我在jetpack compose 中不断收到此错误。 我的错误-

e: learn/app/src/main/java/com/learn/MainActivity.kt: (41, 32): Unresolved reference: fillMaxSize

我的代码

class MainActivity : ComponentActivity() {
    
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme{
                loginUI()
            }
        }
    }
}

@Composable
fun Greeting(){
   
    val image: Painter = painterResource(id = R.drawable.ic_launcher_background)
    Image(painter = image,contentDescription = "")
    Column(modifier = Modifier.fillMaxSize()){
        Text("Hello")
        Text("World")
    }
}

我有这些进口品

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material3.Text
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.Modifier
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import androidx.compose.foundation.layout.Column
import androidx.compose.material.MaterialTheme
import androidx.compose.foundation.Image
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource

这些依赖关系

implementation 'androidx.core:core-ktx:1.9.0'
    implementation "androidx.compose.ui:ui:1.3.0-rc01"
    implementation "androidx.compose.material:material:1.3.0-rc01"
    implementation "androidx.compose.material3:material3:1.0.0-rc01"
    implementation "androidx.compose.material3:material3-window-size-class:1.0.0-rc01"
    implementation "androidx.compose.ui:ui-tooling-preview:1.3.0-rc01"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
    implementation 'androidx.activity:activity-compose:1.7.0-alpha01'
    implementation "androidx.navigation:navigation-compose:2.5.2"
    implementation "com.google.accompanist:accompanist-systemuicontroller:0.26.5-rc"
    
    //TESTS
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.2.1"
    debugImplementation "androidx.compose.ui:ui-tooling:1.3.0-rc01"

我观看 YouTube 上的教程。 我是 jetpack compose 的新手,所以我做了这个项目来学习 jetpack compose。

我使用AndroidIDE。 这个

帮忙解决这个问题

android kotlin android-jetpack-compose androidx
2个回答
2
投票

您需要像这样导入

fillMaxSize
,它会正常工作

import androidx.compose.foundation.layout.fillMaxSize

0
投票

我导入了,但仍然无法正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.