【发布时间】:2019-07-13 05:02:13
【问题描述】:
我正在开发一个 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",
}
})
我需要查看条形图和图像,并且它必须占据整个手机屏幕。
【问题讨论】:
-
您当前的
<Image />似乎没有发生任何事情。考虑使用<ImageBackground />将图像设置为背景。为它的高度和宽度设置一个值。您还可以考虑为条形添加一些顶部和底部填充。 -
感谢您的帮助!我正在使用屏幕相当大的手机。如果被小屏幕手机使用,我该如何适应?
标签: css react-native flexbox