javascript - 如何在反应原生 android 应用程序中显示图像?
问题描述
我想让图像占据设备屏幕的全宽。我尝试了多个 CSS 代码,但它不需要全屏。
代码:
<View style={styles.container}>
<View>
<Image source={require('./Images/rectangle/rectangle.png')} style={styles.backgroundImage}>
</Image>
</View>
</View>
const styles = StyleSheet.create({
container: {
flex: 1
},
backgroundImage: {
height: 200,
flexDirection: 'column',
alignSelf: 'stretch'
}
});
上面的 css 不起作用,我在图像右侧得到空白,请参见屏幕截图:
我还添加了具有不同后缀的图像,以便它适用于不同的屏幕,请参见下面的屏幕截图:
解决方案
试试这个:
backgroundImage:{
width: Dimension.get('window').width ,
alignSelf: 'center',
height: 200,
}
推荐阅读
- reactjs - D3 条形图 + React Hooks - exit().remove() 不起作用
- excel - 如果满足条件,则复制选定的单元格
- c# - Windows 窗体,如何在初始化后向窗体添加控件而不与同一窗体中的相邻控件重叠?
- python - 用python重命名目录中的多个文件夹
- php - 从 php 中的站点获取部分 youtube 链接
- php - slowAES 解密到另一个密钥
- c++ - begin() 是一个有效的迭代器操作,如果是,它指的是什么?
- sql - 缩短表名
- c++ - 如何从头开始列出 C++ 中 ZIP 存档的所有文件名?
- javascript - 为什么 await 执行 mongoose 的查询?