英文:
Why Coil is not loading Images from Repository?
问题
我正在使用Coil库从Firebase加载图像到我的项目中。小尺寸的图像可以成功加载,但大尺寸的图像无法加载。我已尝试了一切方法,但不知道为什么这些图像无法加载。这是我的代码:
@Composable
fun AdvertisementBanner(advertiseList: List<Categories>) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
) {
Banner(advertiseList = advertiseList)
}
}
@Composable
fun Banner(advertiseList: List<Categories>) {
LazyRow(
modifier = Modifier.height(200.dp),
horizontalArrangement = Arrangement.spacedBy(3.dp)
) {
items(advertiseList.size) {
if (advertiseList[it].type == "AdvertisementBanner") {
BannerItem(
backgroundColor = Color.White,
imagePainter = advertiseList[it].url!!
)
}
}
}
}
@Composable
fun BannerItem(
backgroundColor: Color,
imagePainter: String
) {
Card(
modifier = Modifier
.width(300.dp)
.padding(5.dp),
elevation = CardDefaults.cardElevation(
defaultElevation = 5.dp
),
colors = CardDefaults.cardColors(
containerColor = Color.White
)
) {
LoadImages(imagePainter)
}
}
@Composable
fun LoadImages(imagesUrl: String?) {
AsyncImage(
model = imagesUrl, contentDescription = "repository images", contentScale =
ContentScale.Fit, modifier = Modifier.width(300.dp)
)
}
请告诉我如何修复它。
英文:
I am using Coil library to load images from Firebase in my project. Small Images are able to load successfully but large size images are not loading. I have tried all ways to make it happen but not getting why these are not loading. This is my code
@Composable
fun AdvertisementBanner(advertiseList: List<Categories>) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
) {
Banner(advertiseList = advertiseList)
}
}
@Composable
fun Banner(advertiseList: List<Categories>) {
LazyRow(
modifier = Modifier.height(200.dp),
horizontalArrangement = Arrangement.spacedBy(3.dp)
) {
items(advertiseList.size) {
if (advertiseList[it].type == "AdvertisementBanner") {
BannerItem(
backgroundColor = Color.White,
advertiseList[it].url!!
)
}
}
}
}
@Composable
fun BannerItem(
backgroundColor: Color,
imagePainter: String
){
Card(
modifier = Modifier
.width(300.dp)
.padding(5.dp),
elevation = CardDefaults.cardElevation(
defaultElevation = 5.dp
),
colors = CardDefaults.cardColors(
containerColor = Color.White
)
) {
LoadImages(imagePainter)
}
}
@Composable
fun LoadImages(imagesUrl: String?) {
AsyncImage(
model = imagesUrl, contentDescription = "repository images", contentScale =
ContentScale.Fit, modifier = Modifier.width(300.dp)
)
}
Please tell me how do i fix it.
答案1
得分: 1
I use coil
like this to load bigger images. give it a try, hope it works.
英文:
val painter = rememberAsyncImagePainter(
ImageRequest.Builder(LocalContext.current).data(data = imgUrl)
.apply(block = fun ImageRequest.Builder.() {
placeholder(placeholder)
scale(Scale.FILL)
}).build()
)
Image(
painter = painter,
contentDescription = contentDescription,
mod.fillMaxSize(),
contentScale = scale
)
I use coil
like this to load bigger images. give a a try, hope it works.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论