react-native - 如何设置两个按钮粘在一起?
问题描述
我设置了两个半椭圆形按钮并尝试将位置设置在中心。
但我发现他们不粘在一起,我尝试改变justifyContent: 'space-between'
或'space-around'
不工作。
如何让左键和右键粘在一起?
这是我的代码:
return (
<View style={{ justifyContent: 'center', marginTop: 50, flexDirection: 'row', backgroundColor: 'blue' }}>
<TouchableOpacity style={[styles.buttonStyle, { width: 150, height: 50, borderBottomLeftRadius: 50, borderBottomRightRadius: 0, borderTopLeftRadius: 50, borderTopRightRadius: 0 }]}>
<Text>Left</Text>
</TouchableOpacity>
<TouchableOpacity style={[styles.buttonStyle, { backgroundColor: 'orange', width: 150, height: 50, borderBottomLeftRadius: 0, borderBottomRightRadius: 50, borderTopLeftRadius: 0, borderTopRightRadius: 50 }]}>
<Text>Right</Text>
</TouchableOpacity>
</View>
);
const styles = StyleSheet.create({
buttonStyle: {
alignSelf: 'stretch',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'pink',
borderWidth: 1,
borderColor: 'transparent',
marginLeft: 5,
marginRight: 5
},
});
解决方案
删除边距,
buttonStyle: {
alignSelf: 'stretch',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'pink',
borderWidth: 1,
borderColor: 'transparent',
marginLeft: 5,//this
marginRight: 5// this
},
推荐阅读
- laravel - 为什么用户凭据在我的登录单元测试中不起作用?
- vue.js - 无法使用“import * as name from './module', webpack 在 Vue 中返回错误
- django - TweepError at / Unable to access file: No such file or directory when I use can
- typescript - 如何在 Typescript 中使用 Ghost 的 api 从异步函数中获取对象属性
- reactjs - react-multi-carousel 显示右侧有间隙
- c++ - DirectX 获取特定的 mipmap
- node.js - 为什么从另一个调用的函数不会显示在节点应用程序的配置文件输出中?
- jmeter - JMeter,暂停一个 HTTP 调用,同时允许其他调用继续
- javascript - 使用显示块 CSS Javascript 获取模式淡入
- r - 为复杂匹配生成组 ID