我使用了react-native + native-base,并使用了一个简单的布局页眉内容页脚。我在部分中使用MapView,我希望地图填充内容区域。如果我在MapView的样式中指定了宽度和高度,那么地图显示得很好。如果我将MapView的样式设置为flex :1,则不会显示地图
这是我的代码..我想要的就是让地图填充内容..
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
MapView
} from 'react-native';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Icon } from 'native-base';
class Project extends Component {
render() {
return (
<Container>
<Header>
<Title>TEST</Title>
</Header>
<Content>
<MapView
style={styles.map}
showsUserLocation={true}
/>
</Content>
<Footer>
<FooterTab>
<Button transparent>
<Icon name='ios-call' />
</Button>
</FooterTab>
</Footer>
</Container>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
map:{
flex:1
}
});
AppRegistry.registerComponent('Project', () => Project);
发布于 2016-11-10 17:19:32
尝试将<MapView>包装在<View>中而不是<Content>中
<View style={{flex: 1}}>
<MapView
style={styles.map}
showsUserLocation={true}/>
</View>发布于 2016-11-09 20:17:57
Native Base container是一个可滚动的视图,因此您不能在此容器中填充地图。如果检查map元素,高度为0。
一种可能的解决方案是检测窗口尺寸,然后在代码中计算宽度和高度。但要小心调整窗口框架的大小或旋转。
import Dimensions from 'Dimensions'; Dimensions.get('window').height; Dimensions.get('window').width;
发布于 2020-03-30 14:14:30
我有如下内容:
<Container>
<Header>
<Title> My Map</Title>
</Header>
<Map />
<Container> https://stackoverflow.com/questions/40161791
复制相似问题