[英]Create two vertical buttons react native
I've been trying to create a modal with two vertical buttons which take 50% of the width of the rectangle each. 我一直试图用两个垂直按钮创建一个模态,每个按钮占据矩形宽度的50%。 I tried the following code but it seems to give me an unwanted results, that the box is squeezed down to the size of the text instead of stretching.
我尝试了以下代码,但似乎给了我不想要的结果,因为该框被压缩为文本的大小,而不是拉伸。
<Modal
animationType="slide"
isVisible={this.state.isModalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
}}>
<View style={{flex:1, justifyContent: 'center'}}>
<View style={{height: 400, backgroundColor: '#fff', padding: 20}}>
<Text>Want to call ?</Text>
<View style={{flex:1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', borderWidth: 1}}>
<TouchableOpacity onPress={() => this.setState({isModalVisible: false})}>
<View style={{flex:1 ,height: 40,backgroundColor: '#822A80'}}>
<Text>Cancel</Text>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({isModalVisible: false})}>
<View style={{flex:1 , height: 40, backgroundColor: '#50AFAD'}}>
<Text>Yes!</Text>
</View>
</TouchableOpacity>
</View>
</View>
</View>
</Modal>
First of all define width and height and use flexdirection like example: 首先定义宽度和高度,并使用flexdirection,例如:
render() {
return (
// Try setting `flexDirection` to `column`.
<View style={{flex: 1, flexDirection: 'row'}}>
<TouchableOpacity onPress={() => this.setState({isModalVisible: false})}>
<View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({isModalVisible: false})}>
<View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />
</TouchableOpacity>
</View>
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.