RN 设置背景图片(使用ImageBackground组件)

在RN版本0.46版本的时候添加了ImageBackground控件。ImageBackground可以设置背景图片,使用方法和image一样,里面嵌套了其他的组件

javascript 复制代码
import React from "react";
import { ImageBackground, StyleSheet, Text, View } from "react-native";

const image = { uri: "https://zh-hans.reactjs.org/logo-og.png" };

const App = () => (
  <View style={styles.container}>
    <ImageBackground source={image} style={styles.image}>
      <Text style={styles.text}>Inside</Text>
    </ImageBackground>
  </View>
);

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: "column"
  },
  image: {
    flex: 1,
    resizeMode: "cover",
    justifyContent: "center"
  },
  text: {
    color: "white",
    fontSize: 42,
    fontWeight: "bold",
    textAlign: "center",
    background: "#000000a0"
  }
});

export default App;

参考链接:

https://www.reactnative.cn/docs/imagebackground

https://chat.xutongbao.top/

相关推荐
浩星4 小时前
react的框架UmiJs(五米)
前端·javascript·react.js
Niyy_7 小时前
前端一个工程构建多个项目,记录一次工程搭建
前端·javascript
快乐非自愿8 小时前
常用设计模式:工厂方法模式
javascript·设计模式·工厂方法模式
十年磨一剑~9 小时前
html+js开发一个测试工具
javascript·css·html
汪汪队立大功1239 小时前
JavaScript是怎么和html元素关联起来的?
开发语言·javascript·html
格鸰爱童话9 小时前
next.js学习——react入门
学习·react.js·node.js
宋辰月12 小时前
学习react第三天
前端·学习·react.js
GISer_Jing12 小时前
Node.js 开发实战:从入门到精通
javascript·后端·node.js
5335ld13 小时前
后端给的post 方法但是要求传表单数据格式(没有{})
开发语言·前端·javascript·vue.js·ecmascript
QDKuz13 小时前
掌握Vue2转Vue3, Options API 转 Composition API
前端·javascript·vue.js