gpt4 book ai didi

react-native - TouchableHighlight和TouchableOpacity影响Android上的布局

转载 作者:行者123 更新时间:2023-12-04 06:17:00 28 4
gpt4 key购买 nike

我注意到用TouchableWithoutFeedbackTouchableHighlight替换TouchableOpacity可能会导致布局差异。这是预期的吗?

例子:

<TouchableWithoutFeedback onPress={this.onClick}>
<View style={styles.row_container}>
<Text style={styles.row_text}>
{'I count the number of taps: ' + this.state.clicks}
</Text>
</View>
</TouchableWithoutFeedback>

TouchableWithoutFeedback:

TouchableWithoutFeedback

TouchableOpacity替换它:

TouchableHighlight

样式是:
row_container: {
backgroundColor: 'rgba(0, 0, 0, 0.1)',
flex: 1,
height: 100,
borderColor: '#333333',
borderWidth: 1,
borderRadius: 5,
padding: 5,
},
row_text: {
flex: 1,
fontSize: 18,
alignSelf: 'center',
},

最佳答案

解决方案是不引入包装器 View 。只需直接在TouchableHighlightTouchableOpacity上设置样式即可:

<TouchableOpacity onPress={this.onClick} style={styles.row_container}>
<Text style={styles.row_text}>
{'I count the number of taps: ' + this.state.clicks}
</Text>
</TouchableOpacity>

关于react-native - TouchableHighlight和TouchableOpacity影响Android上的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32912556/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com