在下面给出的图像中,您可以看到名称,并且电子邮件未在视图中间对齐。所以,我想将它们精确地对准此垂直视图的中间-
我还在下面提供了此类的代码-
import React, {Component} from "react";
import {View, Text, StyleSheet, ScrollView, Image} from 'react-native';
import {Container, Content, Icon, Header, Body} from 'native-base';
import {DrawerNavigator, StackNavigator, DrawerItems, SafeAreaView} from 'react-navigation';
import NoteMeHome from '../components/NoteMeHome';
import SettingsScreen from '../components/SettingsScreen';
import {Root} from 'native-base';
import {Font, AppLoading} from 'expo';
class HomeDrawer extends Component {
constructor(props) {
super(props);
this.state= {loading:true};
}
async componentWillMount() {
await Font.loadAsync ({
Roboto: require('native-base/Fonts/Roboto.ttf'),
Roboto_medium: require('native-base/Fonts/Roboto_medium.ttf')
});
this.setState({loading:false});
}
render() {
if(this.state.loading) {
return(
<Root>
<AppLoading/>
</Root>
)
}
return(
<MyApp/>
)
}
}
const CustomDrawerContentComponent = (props) => (
<Container style={styles.Container}>
<Header style={styles.drawerHeader}>
<Body style={styles.drawerBody}>
<Image
style={styles.drawerImage}
source={{uri: 'https://img.icons8.com/ios/50/000000/administrator-male-filled.png'}}
/>
<View style={styles.drawerHeaderText}>
<Text>S. M. Asif Ul Haque</Text>
<Text>asif@abc.com</Text>
</View>
</Body>
</Header>
<Content>
<DrawerItems {...props}/>
</Content>
</Container>
);
const MyApp = DrawerNavigator({
NoteMeHome:{
screen: NoteMeHome
},
Settings:{
screen: SettingsScreen
}
},
{
initialRouteName: 'NoteMeHome',
drawerPosition: 'left',
contentComponent: CustomDrawerContentComponent,
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle'
}
);
const styles = StyleSheet.create({
Container:{
textAlign:'center'
},
drawerHeader:{
height:200,
textAlign:'center',
backgroundColor: 'white'
},
drawerHeaderText:{
flex:1,
alignItems:'center',
justifyContent:'center',
backgroundColor:'#5555'
},
drawerImage:{
height: 100,
width: 100,
borderRadius: 75
},
drawerBody: {
flexDirection:'row',
justifyContent:'space-between',
textAlign:'center',
backgroundColor:'#aaaa'
}
});
export default HomeDrawer;
那么,我应该如何将它们垂直对齐到抽屉标题的中间?
答案 0 :(得分:2)
在alignItems:'center'
样式中设置drawerBody