系统提供了增大响应热区的API:responseRegion。需要传递4个参数,
x方向坐标
y方向坐标
width响应的宽度(支持百分比和具体长度)
height响应的高度(支持百分比和具体长度)
具体使用如下:
import Prompt from '@system.prompt'
//热区
@Entry
@Component
struct OfficialRectanglePage {
@State message: string = 'Hello World'
@State textW: number = 0 //热区组件宽度
@State textH: number = 0 //热区组件高度
build() {
Row() {
Column() {
Text(this.message)
.fontSize(30)
.fontWeight(FontWeight.Bold)
.backgroundColor(Color.Orange)
//监听组件的大小变化,来动态的设置响应区域大小
.onAreaChange((oldValue,newValue) => {
this.textW = new Number(newValue.width).valueOf()
this.textH = new Number(newValue.height).valueOf()
})
.responseRegion({
x:-50, //x方向从-50vp开始响应
y:-80,