增加窗口小部件的点击检测区域? [英] Increase tap detection area of a widget?

查看:55
本文介绍了增加窗口小部件的点击检测区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以增加特定窗口小部件的点击区域"?

I was wondering if it is possible to increase the "tap area" of a specific widget?

一个小例子是50 x 50按钮.如果用户在那50 x 50像素上的任意位置点击,将执行按钮的onPressed.但是,我可以这样做吗,如果用户单击按钮上方的5个像素,它的onPressed仍将执行?

A small example would be a 50 by 50 button. If a user taps anywhere on those 50 by 50 pixels the button's onPressed would be executed. However can I make it so that if a user clicks lets say 5 pixels above the button, its onPressed would still be executed?

我只是想增加此区域以提供更好的用户体验,而不必增加按钮的实际大小,这会使UI变得更糟.

I just want to increase this area to provide a better user experience without having to increase the actual size of the button which would make the UI worse.

推荐答案

我对此有些迟,但是您有2个选择.

I'm a bit late to this, however you kinda got 2 options.

我面前的答案是非常基本的,仅使用对您无济于事的基本容器.

The answers before me are very basic and only use basic containers which wont help you.

1)在gestureDetector上使用behavior: HitTestBehavior.translucent,这将允许触摸不可见的内容.但是,您想要的不仅仅是设置为可点击的区域,因此请转到选项2.

1) Use behavior: HitTestBehavior.translucent on your gestureDetector, this will allow invisible things to be tapped. However you want more than the area you set to be tappable so go to option 2.

2)使用不可见的堆栈.在按钮上方堆叠一个容器,使其不可见,并使用正确的HitTestBehaviour在其上添加手势检测,这应该可以正常工作.如果您的按钮是50x50,则将容器设置为55x55,然后将其堆叠在彼此的顶部,然后问题解决.

2) Use an invisible Stack. Stack a container above your button, make it invisible, add gesture detection on it, with the correct HitTestBehaviour, and this should work fine. If your button is 50x50, make the container 55x55 and stack them on top of eachother, and problem solved.

这篇关于增加窗口小部件的点击检测区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆