css - 我需要一张图片来占用它可以占用的最大空间,无论其原始大小如何
问题描述
我正在开发一个 react-native 应用程序,我有一个顶栏和一个底栏。在这两个条之间有一个图像,我需要它占用它可以占用的最大空间,而不管图像的原始大小如何,而不会妨碍两个条。我已经尝试了一段时间,但我无法弄清楚如何做到这一点。
我用 flexbox 尝试了很多东西并设置图像大小,但我无法让它工作。
import React from 'react';
import { StyleSheet, Text, View, Image } from 'react-native';
import Topbar from './topbar.js'
export default function App() {
return (
<View style = {{
flex: 1,
flexDirection: 'column',
justifyContent: 'space-between'
}}>
<View>
<Topbar />
</View>
<View>
<Image source={require('./image2.jpg')} />
</View>
<View>
<Topbar />
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
// here are my bars
import React, { Component } from "react";
import {
Image, StyleSheet, View, Text,Dimensions
} from "react-native";
import Animated from "react-native-reanimated";
const {screenwidth, screenheight } = Dimensions.get("window");
export default class Topbar extends Component {
render() {
return (
<View style ={{
width: screenwidth,
height: 80,
backgroundColor: "#C0C0C0",
flexDirection: 'row',
justifyContent: 'space-between',
}}>
</View>
)
}
}
const styles = StyleSheet.create({
topbarbackground: {
width: screenwidth,
height: 80,
backgroundColor: "#C0C0C0",
}
})
我需要查看条形图和图像,它必须占据整个手机屏幕。
解决方案
我不太确定你想要得到什么。您可以尝试使用ImageBackground
组件并将其设置resizeMode
为cover
. 例子:
覆盖整个屏幕
<ImageBackground
source={img}
imageStyle={{ resizeMode: 'cover' }}
style={{ width: '100%', height: '100%' }}>
<Topbar/>
<View style={{ flex: 1 }}/>
<Bottombar/>
</ImageBackground>
覆盖可用空间
<View style={{ flex: 1 }}>
<Topbar/>
<ImageBackground
source={img}
imageStyle={{ resizeMode: 'cover' }}
style={{ width: '100%', flex: 1 }}/>
<Bottombar/>
</View>
推荐阅读
- c# - 单击 VR 中的游戏对象并做某事
- powershell - 有什么方法可以更改 Powershell ISE 的突出显示颜色?
- r - 将 df$var 传递给函数时,是否可以获得“var”的名称?
- php - 使用文件哈希名称 Laravel 查看图像
- jquery - 我想在“main-img”功能区中激活一个“.next-img”点击事件
- android - 上传到 Google Playstore 后出现错误
- php - 如何在服务器中调试帖子并获取 php 脚本
- android - 获取 2 列 sqlite 的差异总和
- java - 项目在 IDE 中编译,但不在 Maven 中
- java - 添加依赖项后出现 UnsatisfiedDependencyException