【问题标题】:Rounded corners on inside in Jetpack ComposeJetpack Compose 内部的圆角
【发布时间】:2023-01-23 20:18:31
【问题描述】:

是否有选项可以像图片中那样在内部转角?我试过CutCornerShape,但它直接切断了

【问题讨论】:

    标签: android-jetpack-compose


    【解决方案1】:

    你这样的东西

    @Composable
    private fun DrawTicketPathWithArc() {
        Canvas(modifier = canvasModifier) {
    
            val canvasWidth = size.width
            val canvasHeight = size.height
    
            // Black background
            val ticketBackgroundWidth = canvasWidth * .8f
            val horizontalSpace = (canvasWidth - ticketBackgroundWidth) / 2
    
            val ticketBackgroundHeight = canvasHeight * .8f
            val verticalSpace = (canvasHeight - ticketBackgroundHeight) / 2
    
            // Get ticket path for background
            val path1 = ticketPath(
                topLeft = Offset(horizontalSpace, verticalSpace),
                size = Size(ticketBackgroundWidth, ticketBackgroundHeight),
                cornerRadius = 20.dp.toPx()
            )
            drawPath(path1, color = Color.Black)
    
            // Dashed path in foreground
            val ticketForegroundWidth = ticketBackgroundWidth * .95f
            val horizontalSpace2 = (canvasWidth - ticketForegroundWidth) / 2
    
            val ticketForegroundHeight = ticketBackgroundHeight * .9f
            val verticalSpace2 = (canvasHeight - ticketForegroundHeight) / 2
    
            // Get ticket path for background
            val path2 = ticketPath(
                topLeft = Offset(horizontalSpace2, verticalSpace2),
                size = Size(ticketForegroundWidth, ticketForegroundHeight),
                cornerRadius = 20.dp.toPx()
            )
            drawPath(
                path2,
                color = Color.Red,
                style = Stroke(
                    width = 2.dp.toPx(),
                    pathEffect = PathEffect.dashPathEffect(
                        floatArrayOf(20f, 20f)
                    )
                )
            )
        }
    }
    

    检查这个page

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-23
      • 1970-01-01
      • 1970-01-01
      • 2021-12-13
      • 2022-12-06
      • 1970-01-01
      • 1970-01-01
      • 2022-12-10
      相关资源
      最近更新 更多