【发布时间】:2016-03-04 20:24:59
【问题描述】:
我是 flexbox 的新手,无法在 react-native 中生成全宽按钮。一天多来,我一直试图自己弄清楚这一点,并且阅读了互联网上的所有相关文章/帖子,但无济于事。
我想要两个跨越整个屏幕宽度的TextInput 元素,在它们下方有一个也跨越整个屏幕宽度的按钮。 TextInput 元素 跨越了整个屏幕宽度,但这似乎是我正在运行的 Android 模拟器的默认设置。
这是我的代码:
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 跨越屏幕的整个宽度吗?
【问题讨论】:
标签: reactjs react-native flexbox