【问题标题】:Android Jetpack Compose - Floating Action Button of custom imageAndroid Jetpack Compose - 自定义图像的浮动操作按钮
【发布时间】:2022-01-30 19:49:18
【问题描述】:

我写了这段代码。

    Image (
        painter = painterResource(id = R.drawable.image),
        contentDescription = "fab",
        modifier = Modifier
            .size(80.dp)
            .clickable(
                interactionSource = remember { MutableInteractionSource() },
                indication = rememberRipple(true),
                onClick = { /* TODO */ }
            )
    )

但是,我使用脚手架。 所以我想使用浮动操作按钮或扩展浮动操作按钮。 如何使用浮动操作按钮和自定义图像。 我有一张圆形照片可用于按钮。

    Scaffold(
        topBar = {},
        content = {},
        floatingActionButton = {
            Image {
                /* How can I wrire */
            }
        }
    )

【问题讨论】:

    标签: android android-jetpack-compose scaffold


    【解决方案1】:

    你可以使用类似的东西:

    Scaffold(
        topBar = {},
        content = {},
        floatingActionButton = {
            FloatingActionButton(onClick = { /*TODO*/ }) {
                Image (
                    painter = painterResource(id = R.drawable.xxxx),
                    contentDescription = "fab",
                    contentScale = ContentScale.FillBounds
                )
            }
        }
    )
    

    【讨论】:

    • 非常感谢!但是,这张图片周围有一个边距。
    • @vr_min_chan 添加适当的 contentScale(检查更新的答案)
    猜你喜欢
    • 2022-06-25
    • 2021-10-21
    • 2019-12-15
    • 2015-08-07
    • 2015-12-07
    • 2020-05-11
    • 1970-01-01
    • 2020-07-17
    相关资源
    最近更新 更多