HarmonyOS 父元素的阴影被子元素覆盖

Column() {
  Column()
    .width(100)
    .height(100)
    .margin({
      top: 50,
      left: 50
    })
    .border({
      width: 2,
      color: Color.Red
    })
    .backgroundColor(Color.White)
}
.width(100)
.height(100)
.border({
  width: 2
})
.shadow({
  offsetX: 0,
  offsetY: 0,
  radius: 20,
  color: Color.Red
})

这样的结构子元素超出了父级的范围但是父级的边框是覆盖在子级上的阴影却没了。如何才能将阴影显示在子级上?

HarmonyOS
2025-01-09 16:37:20
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

示例参考如下:

@Entry
@Component
struct TestPage {
  @State message: string = 'Hello World';

  build() {
    Stack() {
      Column()
        .width(100)
        .height(100)
        .margin({
          top: 50,
          left: 50
        })
        .border({
          width: 2,
          color: Color.Red
        })
        .backgroundColor(Color.White)
      Column() {

      }
      .width(100)
      .height(100)
      .border({
        width: 2
      })
      .shadow({
        offsetX: 0,
        offsetY: 0,
        radius: 20,
        color: Color.Red
      })
    }
  }
}

当子级的点击事件需要穿透到父级时,可以通过设置组件的hitTestBehavior属性来实现。可参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-hit-test-behavior-V5#hittestmode枚举说明

分享
微博
QQ
微信
回复
2025-01-09 18:37:23
相关问题
HarmonyOS NavPathStack如何删除元素
321浏览 • 1回复 待解决
HarmonyOS 动态隐藏页面元素
392浏览 • 1回复 待解决
HarmonyOS 元素高度排版异常
143浏览 • 1回复 待解决
HarmonyOS ArkUI获取元素坐标位置
338浏览 • 1回复 待解决
HarmonyOS list元素拖动换位置实现
251浏览 • 1回复 待解决
如何实现共享元素转场
678浏览 • 1回复 待解决
Record<string, string>如何删除里边元素
1854浏览 • 1回复 待解决
HarmonyOS 咨询共享元素动态转场示例
841浏览 • 1回复 待解决
怎么设置元素最大宽度最小宽度?
563浏览 • 1回复 待解决
readonly修饰数组无法获取数组元素
2615浏览 • 1回复 待解决
如何获取元素位置和大小
2497浏览 • 1回复 待解决