【发布时间】:2021-03-16 05:19:17
【问题描述】:
我试图让两个大按钮 (TouchableOpacity) 彼此相邻并占据屏幕宽度的 50%。
但它们似乎只与其中的文本组件一样宽。
如何让两个 TouchableOpacity 占据整个屏幕的宽度,每个占据 50% 的宽度?
const styles = StyleSheet.create({
container: {
flexDirection: 'row',
backgroundColor: 'lightblue',
height: 200,
justifyContent: 'space-around',
},
btn: {
flex: 1,
backgroundColor: 'red',
justifyContent: 'center',
padding: 20,
borderWidth: 1,
},
});
return (
<View style={styles.container}>
<TouchableOpacity style={styles.btn}>
<Text>Left</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.btn}>
<Text>Right</Text>
</TouchableOpacity>
</View>
);
【问题讨论】:
标签: react-native