gpt4 book ai didi

android-jetpack-compose - Jetpack 撰写 LazyColumn + Coil-Compose 不起作用

转载 作者:行者123 更新时间:2023-12-02 18:21:54 25 4
gpt4 key购买 nike

Jetpack 组合项目

我用的是Coil-Compose rememberImagePainter

依赖关系{

implementation 'io.coil-kt:coil-compose:1.4.0'

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ApplicationTheme {
Surface(color = MaterialTheme.colors.background) {
Image(
painter = rememberImagePainter("https://api.dujin.org/bing/1366.php"),
contentDescription = null
)
}
}
}
}
}

enter image description here

添加 LazyColumn 不起作用

…………
import coil.compose.rememberImagePainter
…………

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ApplicationTheme {
Surface(color = MaterialTheme.colors.background) {
+ LazyColumn {
+ items(10) {
Text(text = "test")
// doesn't work
Image(
painter = rememberImagePainter("https://api.dujin.org/bing/1366.php"),
contentDescription = null
)
+ }
+ }
}
}
}
}
}

enter image description here

请帮帮我

最佳答案

在LazyColumn或者LazyRow中使用本地资源是没有问题的,但是网络图片需要指定宽高

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ApplicationTheme {
Surface(color = MaterialTheme.colors.background) {
LazyColumn {
items(10) {
Text(text = "test")
// doesn't work
Image(
painter = rememberImagePainter("https://api.dujin.org/bing/1366.php"),
contentDescription = null,
Modifier.fillMaxSize().height(300.dp)
)
}
}
}
}
}
}
}

关于android-jetpack-compose - Jetpack 撰写 LazyColumn + Coil-Compose 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70764690/

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