我是flexbox的新手,无法在react- native中产生全角按钮。我已经花了整整一天的时间来解决这个问题,并且在互联网上阅读了所有相关文章/帖子都无济于事。
我希望有两个TextInput元素可以覆盖整个屏幕宽度,下面有一个按钮也可以覆盖整个屏幕宽度。该TextInput元素 是 横跨屏幕的整个宽度,但是这似乎是在默认情况下在Android模拟器我跑。
TextInput
这是我的代码:
var MyModule = React.createClass({ render: function() { return ( <View style={styles.container}> <View style={styles.headline}> <Text>Hello World</Text> </View> <View style={styles.inputsContainer}> <TextInput style={[styles.input]} placeholder="Email" /> <TextInput secureTextEntry={true} style={[styles.input]} placeholder="Password" /> <TouchableHighlight style={styles.fullWidthButton} onPress={this.buttonPressed} > <Text>Submit</Text> </TouchableHighlight> </View> </View> ); }, buttonPressed: function() { console.log("button was pressed!"); } }); var paddingLeft = 15; var styles = StyleSheet.create({ inputsContainer: { // Intentionally blank because I've tried everything & I'm clueless }, fullWidthButton: { // Intentionally blank because I've tried everything & I'm clueless }, input: { paddingLeft: paddingLeft, height: 40, borderColor: "black", backgroundColor: "white" }, container: { flex: 1, backgroundColor: "#f0f0f0", alignItems: "stretch" }, headline: {} }); module.exports = Onboarding;
有人知道我需要做些什么TouchableHighlight才能跨越屏幕的整个宽度吗?
TouchableHighlight
我来这里寻找相同的问题。经过进一步实验,我发现最简单的方法是使用alignSelf: 'stretch'。这迫使单个元素占用可用的全部宽度,例如
alignSelf: 'stretch'
button: { alignSelf: 'stretch' }
Nader的答案当然可以,但是这似乎是使用Flexbox的正确方法。