【问题标题】:Adjust ImageBackground to fullscreen将 ImageBackground 调整为全屏
【发布时间】:2019-04-04 19:53:58
【问题描述】:

我提供了一个 ImageBackground 组件,我希望它占据整个屏幕,但即使我调整图像大小两次或更多,它似乎也有小填充。它来自哪里?

Here is the code of the component

import React from "react";
import { View, Text, Button, ImageBackground, StyleSheet } from "react- 
native";

export class HomeScreen extends React.Component {

static navigationOptions = {
  //To hide the NavigationBar from current Screen
  header: null
};

render() {
  return (
     <ImageBackground source={require('../imgs/bgx.png')} style={ 
       styles.container }>
     </ImageBackground>
  );
}


}

var styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'stretch',
    resizeMode: 'stretch'
  }
});

【问题讨论】:

  • 兄弟,那张图好大啊……
  • 确保您的原始图片适合 iOS 设备的宽高比,然后特别确保它是 24 BPP(不透明),这意味着图片中没有 Alpha 通道。
  • 看来是这个原因!我已经尝试过另一个图像,它非常适合!谢谢!!

标签: ios react-native imagebackground


【解决方案1】:

确保您的源图像没有周围有任何透明度。

width: '100%'height: '100%' 设置为ImageBackground 组件。有什么改变吗?

【讨论】:

  • @HubertSolecki 您是否尝试过 MoDJ 对您帖子下的宽高比的建议作为评论?
  • 是的,是这样的;)谢谢!
【解决方案2】:

添加width='100%'height='100%'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 2014-09-01
    • 2019-09-14
    相关资源
    最近更新 更多