gpt4 book ai didi

android - 如何使用 Jetpack Compose 在我的屏幕中使用 9 补丁可绘制对象 (.9.png)?

转载 作者:行者123 更新时间:2023-12-05 00:15:14 26 4
gpt4 key购买 nike

我正在尝试在可组合的图像中使用 .9.png 文件:

            Image(
painter = painterResource(id = R.drawable.shadow_faq),
contentDescription = "Faq card 1",
modifier = Modifier
.constrainAs(imgGeneral) {
top.linkTo(glImgGeneralTop)
bottom.linkTo(glImgBottom)
start.linkTo(glImgLeft)
end.linkTo(glImgRight)
height = Dimension.fillToConstraints
width = Dimension.fillToConstraints
}
)
但是在这样做时,我遇到了一个渲染问题,上面写着 java.lang.IllegalArgumentException: Only VectorDrawables and rasterized asset types are supported ex. PNG, JPG如何在 Jetpack Compose 中使用 .9.png 文件?

最佳答案

您可以使用 DrawablePainter 从伴奏者返回 Painter它绘制了一个 Android Drawable .

Image(
rememberDrawablePainter(drawable = ContextCompat.getDrawable(context,R.drawable.xxxx) ),
contentDescription = "Faq card 1"
)
更新 : 从 1.0.0-rc02 开始和伴奏 0.14.0您可以使用 coil-compose版本:
Image(
rememberImagePainter(ContextCompat.getDrawable(context,R.drawable.xxx)),
contentDescription = "Faq card 1",
)

关于android - 如何使用 Jetpack Compose 在我的屏幕中使用 9 补丁可绘制对象 (.9.png)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68314553/

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