Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 反应本机图像未与视图居中_Css_Image_React Native_Flexbox - Fatal编程技术网

Css 反应本机图像未与视图居中

Css 反应本机图像未与视图居中,css,image,react-native,flexbox,Css,Image,React Native,Flexbox,我试图在视图中水平和垂直居中放置图像。问题是,无论我在代码中放置什么,它似乎始终处于同一位置。我在另一个屏幕上为另一个视图设置了此代码,它正是我所需要的,但是对于其他页面,它没有响应 这是我的密码: <View style={styles.header}> <Icon raised name='chevron-left' type='octicon' color='#

我试图在
视图中水平和垂直居中放置
图像
。问题是,无论我在代码中放置什么,它似乎始终处于同一位置。我在另一个屏幕上为另一个
视图
设置了此代码,它正是我所需要的,但是对于其他页面,它没有响应

这是我的密码:

<View style={styles.header}>
        <Icon
            raised
            name='chevron-left'
            type='octicon'
            color='#f50'
            onPress={() => this.props.navigation.goBack()}
            containerStyle={{ alignSelf:'flex-end', marginRight:20, marginTop:-60 }}/>
        <Image source={Logo} style={{resizeMode:'stretch', width:50, height:50, alignItems:'center', marginTop:30, position:'absolute'}}/>
       </View>

const styles = StyleSheet.create({
        header:{
        backgroundColor:'#ff4714', 
        height:SCREEN_HEIGHT/8,
        flexDirection: 'row' 

    }
});

this.props.navigation.goBack()}
containerStyle={{alignSelf:'flex-end',marginRight:20,marginTop:-60}/>
const styles=StyleSheet.create({
标题:{
背景颜色:“#ff4714”,
高度:屏幕高度/8,
flexDirection:“行”
}
});
编辑:我已经删除了
的所有样式,除了
宽度
高度
之外,并且图像保持在同一位置。我不知道该怎么理解这个

以下是世博会小吃

尝试添加:

alignItems: 'center',
justifyContent: 'center'
到您的
标题
样式


您可能还需要添加
flex:1
,这取决于您的
视图的状态

您需要在图像样式中添加justifyContent:“center”和alignSelf:“center”

只需检查代码:

 <View style={{
        flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
      }}>
       <Image source={{uri:'https://source.unsplash.com/random'}} style={{height:50,width:50,alignSelf:'center'}}         />
      </View>

这是世博小吃:

更新:

这是我最新的世博小吃:


希望有帮助

它似乎不起作用。我编辑了我的问题以获得更多的见解我编辑了我的问题,出于某种原因,我什么也不做会改变图片的位置。为了同样的乐趣,分享一份世博会点心。嘿,更新链接后检查我的答案。如果有,一定要告诉我。任何怀疑都有效!我不知道最后一个
视图
对图像有什么影响,但出于某种原因,没有它这就不行了哈哈。谢谢,因为这是第行的flex Direct。你需要3个组件,第二个才能在中间。因此,需要一个虚拟视图来将图像放置在中心