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/

相关推荐
jjw_zyfx43 分钟前
css vue vite实现闪烁的呼吸效果
javascript·css·vue.js
sunly_1 小时前
React useActionState 的用法详解
前端·javascript·react.js
cyadyx2 小时前
【Three.js】Three.js 中加载 3D 模型
前端·javascript·3d
汉堡大王95272 小时前
前端工程师 TypeScript 上手指南:一条清晰的从入门到精通路线
前端·javascript·react.js
wear工程师2 小时前
防抖为什么会失效?React 面试里的闭包和定时器
javascript·react.js
浅水壁虎2 小时前
vue基础(第四章 Pinia)
前端·javascript·vue.js
张元清3 小时前
React useEventSource Hook:自带断线重连的 Server-Sent Events (2026)
javascript·react.js
光影少年3 小时前
RN 网络请求:Fetch / Axios 封装、超时、拦截器
前端·react native·react.js
铁皮饭盒3 小时前
网页端, 6.5MB人脸识别模型, 谷歌框架, 又快又准
前端·javascript·后端
自进化Agent智能体4 小时前
Hermes 工具与工具集——Hermes 的内置能力
javascript