目录

使用clipShape进行裁剪后,borderRadius无法生效怎么处理

问题现象

对容器组件使用clipShape进行裁剪后,再使用borderRadius对被裁剪容器设置圆角时无法生效,问题代码与问题效果图如下:

import { PathShape } from '@kit.ArkUI';

@Entry
@Component
struct IrregularShape {
  build() {
    Column() {
      Row()
        .width(300)
        .height(200)
        .backgroundColor('rgba(10, 89, 247, 0.3)')
        .clipShape(new PathShape().commands(`M0 0 L500 0 L500 300 L0 150 Z`))
        .borderRadius(20);
    }
    .width('100%')
    .height('100%')
    .justifyContent(FlexAlign.Center)
    .alignItems(HorizontalAlign.Center);
  }
}

背景知识

解决方案

borderRadius属性从规格上是相对于组件的大小而言的,当组件同时设置borderRadius和clipShape时,borderRadius会首先生效,对整个组件设置圆角效果,然后clipShape裁剪效果会覆盖borderRadius的圆角效果,导致borderRadius不生效。

总结