简体   繁体   中英

How align a Content vertically aligned middle in the screen?

In the image given below where you can see the name and the email is not aligned middle of the view. So, I want to align them exactly middle of this vertical view-

在此处输入图片说明

I have also provided the code of this class in the below-

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;

So, What should I do to align them vertically middle of the header of the drawer?

在您的drawerBody设置alignItems:'center'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM