一个适用于Android和Compose Multiplatform的图片加载库。Coil具有以下特点:
- 快速:Coil执行多项优化,包括内存和磁盘缓存、图像下采样、自动暂停/取消请求等。
- 轻量级:Coil仅依赖Kotlin、协程和Okio,与Google的R8等代码压缩工具无缝配合。
- 易用:Coil的API利用Kotlin的语言特性,简化使用并减少样板代码。
- 现代化:Coil以Kotlin为先,并与协程、Okio、Ktor和OkHttp等现代库互操作。
Coil是Coroutine Image Loader的缩写。
翻译:日本語、한국어、Русский、Svenska、Türkçe、中文
下载
Coil可在mavenCentral()
上获取。
implementation("io.coil-kt:coil:2.7.0")
快速入门
Compose
导入Compose扩展库:
implementation("io.coil-kt:coil-compose:2.7.0")
使用AsyncImage
可组合项加载图片:
AsyncImage(
model = "https://example.com/image.jpg",
contentDescription = null,
)
ImageViews
使用load
扩展函数将图片加载到ImageView
中:
imageView.load("https://example.com/image.jpg")
可以通过可选的尾随lambda配置请求:
imageView.load("https://example.com/image.jpg") {
crossfade(true)
placeholder(R.drawable.image)
}
查看Coil的完整文档了解更多信息。
许可证
Copyright 2024 Coil Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.