React Native,<img/>不能包含子代

时间:2018-11-09 20:45:35

标签: javascript react-native

我正在尝试在徽标中放入徽标/图片。我已经在使用BackgroundImage,所以我想将Image放在背景上。检查下面的代码。请帮我弄清楚。

import React from 'react';
import { StyleSheet, Text, View, ImageBackground, Image } from 'react-native';

export default class App extends React.Component {
  render() {
    return (
      <ImageBackground source={require('./app/img/baky.jpeg')} style={styles.container}>
        <View style={styles.inner}>
          <Image source={require('./app/img/logo.png')} style={styles.logo}> </Image>
          <Text style={styles.txt}> Hello!!!! </Text>
        </View>
      </ImageBackground>

    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
  inner: {
    padding: '10%',
    justifyContent: 'center',
    flexDirection: 'row',
    width: '100%',
    height: '100%',
    backgroundColor: 'rgba(255, 255, 255, .7)'
  },
  logo: {
    width: 50,
    height: 50
  },
  txt: {
    color: 'black',

  }
});

1 个答案:

答案 0 :(得分:-2)

只需将<Image source={require('./app/img/logo.png')} style={styles.logo}> </Image>更改为<Image source={require('./app/img/logo.png')} style={styles.logo} />