我使用的是 jetpack compose 1.0.0-alpha 11。下面的代码有效。
Image(
imageResource(R.drawable.header),
contentDescription = null,
modifier = itemModifier,
contentScale = ContentScale.Crop
)
但是在 jetpack compose 1.0.0-beta07 中,imageResource
和 vectorResource
不再有效。
获取图片资源的新方式是什么?
最佳答案
在 1.0.x
中,您可以使用 painterResource
功能:
Image(painterResource(R.drawable.ic_xxxx),"content description")
这可以分别为基于 ImageBitmap
的 Assets 或基于矢量的 Assets 加载 BitmapPainter
或 VectorPainter
的实例。
此方法适用于图像(PNG 或 JPG 文件)或 VectorDrawable
xml Assets 。
关于ImageBitmap.imageResource(R.drawable.header)
的使用
This function is intended to be used for when low-level
ImageBitmap
-specific functionality is required. For simply displaying onscreen, the vector/bitmap-agnosticpainterResource
is recommended instead.
关于android - Unresolved reference : vectorResource and imageResources in Jetpact Compose 1. 0.0-beta07,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67700446/