Android compose crane
Posted aikongmeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android compose crane相关的知识,希望对你有一定的参考价值。
https://github.com/android/compose-samples/tree/main/Crane
A Compose implementation of the Crane Material study, a travel app that uses Material Design components and Material Theming to create a personalized, on-brand experience.
• Medium complexity
• Draggable UI elements
• Android Views inside Compose
• UI state handling
• UI Tests
采用了 kt gradle 脚本, 在Dependencies.kt
定义了要使用类库
如
...
object Coil {
const val coilCompose = "io.coil-kt:coil-compose:1.3.0"
}
object Urls {
const val mavenCentralSnapshotRepo = "https://oss.sonatype.org/content/repositories/snapshots/"
const val composeSnapshotRepo = "https://androidx.dev/snapshots/builds/" +
"${Libs.AndroidX.Compose.snapshot}/artifacts/repository/"
}
Coil
基本用法
Image(
painter = rememberCoilPainter("https://picsum.photos/300/300"),
contentDescription = stringResource(R.string.image_content_desc),
)
支持渐显crossfade,高斯模糊BlurTransformation,圆角 缩放等
val painter = rememberImagePainter(
data = item.imageUrl,
builder = {
crossfade(true)
crossfade(1000)
}
)
Image(
painter = painter,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize(),
)
GIFs 默认不支持, 可以添加支持库 io.coil-kt:coil-gif:1.3.1
分割线
Spacer(Modifier.height(8.dp))
@Composable
fun Spacer(modifier: Modifier) {
Layout({}, modifier) { _, constraints ->
with(constraints) {
val width = if (hasFixedWidth) maxWidth else 0
val height = if (hasFixedHeight) maxHeight else 0
layout(width, height) {}
}
}
}
以上是关于Android compose crane的主要内容,如果未能解决你的问题,请参考以下文章
Android Jetpack compose:使用谷歌地图在地图创建时崩溃
Jetpack Compose 和 Compose Navigation 如何处理 Android 活动?