React native中Android 的图片加载问题

来源:互联网 发布:汉族不平等知乎 编辑:程序博客网 时间:2024/05/21 19:29

在项目的目录:根目录-->android-->app-->src-->main-->res文件夹下新建drawable文件夹,然后将图片放到该文件夹下。

在代码中使用Image加载图片:需要在import中导入Image组件,其次代码:

import React, {Component} from 'react'import {    AppRegistry,    View,    StyleSheet,    Image,} from 'react-native'/** * 在布局的过程中使用到的所有的控件都必须 * 在import中先导入控件,之后才能使用 */export default class LayoutView extends Component {    render() {        return (            <View style={styles.container}>
                <Image source={{uri:'bb'}}                       style={{width: 200, height: 200}}/>
            </View>        )    }}const styles = StyleSheet.create({ //这里的StyleSheet,大小写必须严格控制    container: {        alignItems: 'center',        justifyContent: 'center',        paddingTop: 50,    }});AppRegistry.registerComponent("LayoutView", () => LayoutView);

原创粉丝点击