一般来说,我是 react-native 和移动应用程序开发的新手,我正在尝试为我的应用程序创建一个标题,其中包含一个文本和一个按钮。
这是我的代码:
import React from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
export default class App extends React.Component {
_leaveSheet() {
}
render() {
return (
<View style={styles.container}>
<View style={styles.header}>
<Text allowFontScaling={false} style={styles.titleText}>YATHZEE</Text>
<Button style={styles.leaveButton} title="Quitter" onPress={this._leaveSheet}/>
</View>
<View style={styles.body}></View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'column'
},
header: {
flex: 1,
backgroundColor: '#BDBDBD',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between'
},
body: {
flex: 10,
backgroundColor: 'white'
},
titleText: {
// fontSize: 30,
fontWeight: 'bold',
backgroundColor: 'yellow',
// alignSelf: 'center',
flex: 1
},
leaveButton: {
// alignSelf: 'center',
// width: '100'
flex: 2
}
});
因此,我将带有 flexDirection 的标题放在行中,并在我的视图中添加了我的文本和带有 flex: 1 和 flex: 2 的 Button 元素,所以我期待这个结果:
但相反,我有这个:按钮内的文本被截断,我的按钮没有占用他应该占用的空间。
我尝试使用 alignSelf 属性和宽度,但似乎没有任何效果。
在 facebook Button 示例中,我可以看到 Button 可以定义 Button 的宽度,但我不知道如何使其工作。