在 react-native 中控制可触摸区域 [英] Control touchable area in react-native
问题描述
我有一个方形的 TouchableOpacity
按钮,它的图形只是中间的一个小圆点图标,其余部分是透明背景.我发现在许多 Android 设备中按下它是相当困难的,因为显然只有不透明区域是可触摸的,而其他区域则不可触摸.
I have a square TouchableOpacity
button, whose graphics is just a small dot icon in the middle, and the rest is transparent background.
I find that in many Android devices it's quite difficult to press it, as apparently only the opaque area is touchable, and the rest isn't.
有没有办法控制 TouchableOpacity
或其其他类似按钮的兄弟的可触摸区域?
Is there any way then to control the touchable area of a TouchableOpacity
or its other button-like siblings?
推荐答案
您可以使用 View#hitSlop
属性 增加可触摸区域.这在您知道增加的触摸区域不会与其他可触摸对象重叠的情况下很有用.
You can use the View#hitSlop
property to increase the touchable area. This can be useful in scenarios where you know that the increased touch area won't overlap with other touchables.
更强大的解决方案是使用 padding
样式属性.Touchable*
组件的可触摸区域包括元素的内边距.
A more robust solution is to use the padding
style property. The touchable area of the Touchable*
components includes the element's padding.
这篇关于在 react-native 中控制可触摸区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!