如何查看触摸热区范围

如何查看触摸热区范围

HarmonyOS
2024-07-22 12:29:03
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
kraml

目前只能通过自定义的方式获取responseRegion。参考文档:触摸热区设置

@Entry 
@Component 
struct TouchTargetExample { 
  @State text: string = '' 
  @State x:number = 0 
  @State y:number = 0 
  @State reg_width:string = '50%' 
  @State reg_height:string = '100%' 
 
  build() { 
    Column({ space: 20 }) { 
      Text("{x:0,y:0,width:'50%',height:'100%'}") 
 
      // 热区宽度为按钮的一半,点击右侧无响应 
      Button('button') 
        .responseRegion({ x: this.x, y: this.y, width: this.reg_width, height: this.reg_height }) 
        .onClick(() => { 
          this.text = 'button clicked' 
          console.log('button clicked: '+this.x+' '+this.y+' '+this.reg_width+' '+this.reg_height) 
        }) 
 
      Text(this.text).margin({ top: 10 }) 
    }.width('100%').margin({ top: 100 }) 
  } 
}
分享
微博
QQ
微信
回复
2024-07-22 20:11:50
提问
该提问已有0人参与 ,帮助了0人