简体   繁体   English

喷气背包中的椭圆形组成

[英]Oval shape in jetpack compose

I need to create a custom shape in jetpack compose similar to RoundedCornerShape, the result should look like this:我需要在 jetpack compose 中创建一个类似于 RoundedCornerShape 的自定义形状,结果应该如下所示:

在此处输入图像描述

I believe I should extend the Shape interface like this:我相信我应该像这样扩展 Shape 接口:

class OvalCornerShape : Shape {

override fun createOutline(
    size: Size,
    layoutDirection: androidx.compose.ui.unit.LayoutDirection,
    density: Density
): Outline {
    val rect = size.toRect()

    val path = Path().apply {
        // do work here 
    }
    return Outline.Generic(path)
}

Any idea how I can achieve this ?知道如何实现这一目标吗?

This shape is not an oval or RoundedRect(percent=...).此形状不是椭圆形或 RoundedRect(percent=...)。 If you know mathematical expression you can use GenericShape to create a shape then Modifier.clip or Modifier.background() to set it as your shape.如果您知道数学表达式,则可以使用 GenericShape 创建形状,然后使用 Modifier.clip 或 Modifier.background() 将其设置为您的形状。 Probably requires addArc or quadraticBezier to draw可能需要 addArc 或 quadraticBezier 来绘制

val shape = GenericShape{size,layoutDirection->
    this.quadraticBezierTo()
    this.arcTo()
}

Other option, it would probably be possible with photoshop to remove surrounding white color, to get this shape as an image then use Canvas and BlendMode to crop any image if that's what you need其他选项,可以使用 Photoshop 去除周围的白色,将此形状作为图像,然后使用 Canvas 和 BlendMode 裁剪任何图像,如果这是你需要的

https://raw.githubusercontent.com/SmartToolFactory/Jetpack-Compose-Tutorials/master/screenshots/tutorial6_2.gif https://raw.githubusercontent.com/SmartToolFactory/Jetpack-Compose-Tutorials/master/screenshots/tutorial6_2.gif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM