我想在我的react-native 应用程序中使用背景图像,

但如果图像为loaded from asset bundle,则不起作用

var styles = StyleSheet.create({
  bgImage: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'stretch',
    resizeMode: 'stretch',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  }
});

<Image source={require('image!background')} style={styles.bgImage}>
  <Text style={styles.welcome}>
    Welcome to React Native!
  </Text>
</Image>

看起来是这样的:

在此处输入图像描述

但是,它适用于远程图像,通过source={{uri: 'background-image-uri'}}:

在此处输入图像描述

推荐答案

从Github的问题:Image {require} is broken in React Native for Resizing,你可以试试<Image style={{width: null, height: null}},希望facebook能尽快解决它.

React-native相关问答推荐

领带麦克风在Reaction-Native-Incall-Manager中不工作

react native 如何更新倒置平面列表的数组中的项目

如何在react-native 的switch 内显示文本(是/否)

如何获取 iOS 版本?

如何在带有decorator 的 react-native 0.56 (Babel 7) 中使用 mobx

react-native (expo)加载markdown 文件

react-native-firebase crashlytics 未显示在 firebase 仪表板上

fetch API 总是返回 {"_U": 0, "_V": 0, "_W": null, "_X": null}

ReactNative FlatList 一次渲染所有元素?

React Native 无法读取 index.android.delta

如何使用react钩子设置状态数组

自定义标签栏react Navigation 5

React native + redux-persist:如何忽略键(黑名单)?

FlatList vs map react-native

ENOENT: no such file or directory, 打开 'android/app/src/main/assets/index.android.bundle'

React-native:图像未显示在 android 设备中,但在模拟器中完美显示

试图在一个本应是不可变且已被冻结的对象上设置密钥

在react-native中调试应用程序崩溃

Android 是否支持 React Native 的 LayoutAnimation?

类型 androidx.appcompat.resources.R$dimen 被定义了多次