react-native - 如何设置视图组件的样式以在两个按钮之间添加空间?
问题描述
我是 React Native 前端开发的新手。只是想掌握样式表的窍门。我在具有以下样式的视图中放置了两个按钮。
buttonscontainer: {
flexDirection: 'row',
justifyContent: 'flex-end',
}
这是完整的 jsx 和样式
<Modal transparent={true} visible={true}>
<View style={styles.dimmedBackground}>
<View style={styles.modalContainer}>
<Text>type something</Text>
<TextInput style={styles.input} />
<View style={styles.buttonsContainer}>
<Button title="Cancel" color="coral" />
<Button title="Add" color="coral" />
</View>
</View>
</View>
</Modal>
const styles = StyleSheet.create({
dimmedBackground: {
backgroundColor: '#000000aa',
flex: 1,
justifyContent: 'center',
},
modalContainer: {
backgroundColor: '#ffffff',
margin: 35,
padding: 30,
borderRadius: 10,
},
input: {
marginBottom: 10,
paddingVertical: 6,
borderBottomWidth: 1,
borderBottomColor: '#ddd',
},
buttonsContainer: {
flexDirection: 'row',
justifyContent: 'flex-end',
},
});
一段时间以来,我一直在尝试在两个按钮之间创建空间,对于如何实现这一点非常迷茫。
我应该如何设置包装两个按钮的视图组件的样式,以便它们之间有一点水平空间?谢谢
解决方案
您可以使用 'space-between' 作为理由,提供宽度
buttonscontainer: {
flexDirection: 'row',
justifyContent: 'space-between',
marginHorizontal: 5,
width:'40%',
alignSelf:'flex-end'
},
推荐阅读
- c# - WPF/SQL:用参数替换值?
- angular - 部署 Angular 6 应用程序的问题
- javafx - 创建与 List/ObstableList 值绑定的 BooleanBinding
- python - 无法从 html 中找到所需的内容
: Python BS4 - mysql - SQL 计算一列中的出现次数并计算另一列的总数
- ansible - Ansible 2.7 多行 ansible_managed
- python - 如何在django中连接mysql
- elixir - Elixir GenServer handle_call 回调返回类型
- php - Laravel 邮箱验证 - 强制登录
- python - Django TypeError: url() 接受 2 到 4 个位置参数,但给出了 16 个