React Native组件篇 — Image组件
warning:
这篇文章距离上次修改已过193天,其中的内容可能已经有所变动。
import React from 'react';
import { Image, StyleSheet, Text, View } from 'react-native';
export default class App extends React.Component {
render() {
let pic = {
uri: 'https://reactnative.dev/img/tiny_logo.png'
};
return (
<View style={styles.container}>
<Text>Hello, React Native!</Text>
<Image source={pic} style={styles.logo} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
logo: {
height: 100,
width: 100,
}
});
这段代码展示了如何在React Native应用中导入并显示一个远程图片。它使用了Image
组件,并通过一个URI指向了一个在线图片资源。同时,它还展示了如何使用StyleSheet
来定义样式,这是React Native中管理样式的标准方式。
评论已关闭