我想使用Image.getSize(https://facebook.github.io/react-native/docs/image.html)来获取我的图像的大小,但第一个参数要求图像源在URI中,但我可以不要将URI与静态文件一起使用,我只能使用Require.
因此,是否可以在静态文件上使用Image.getSize或者我必须找到另一种方法?
我想让红色视图保持16:9的比例。我尝试但失败了。我知道React Native使用Flexbox(用Java重新实现),但是我不知道该怎么做。谢谢。
这是我的Javascript:
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
View,
} = React;
var AwesomeProject = React.createClass({
render: function() {
return (
<View style={styles.container}>
<View style={styles.banner}>
</View>
<View style={styles.items}>
</View>
</View>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
},
banner: {
backgroundColor: 'red',
flex: 1,
},
items: {
backgroundColor: 'blue',
flex: 3,
},
});
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
Run Code Online (Sandbox Code Playgroud)
这是关于React Native中Flexbox的文档:
http://facebook.github.io/react-native/docs/flexbox.html#content
这是有效的样式道具:
Valid style props: [
"width",
"height",
"top",
"left",
"right",
"bottom", …Run Code Online (Sandbox Code Playgroud) <Image
style={{
alignSelf: 'center',
flex: 1,
width: '25%',
height: null,
resizeMode: 'cover',
borderWidth: 1,
borderRadius: 75,
}}
source={{uri:'https://facebook.github.io/react/img/logo_og.png'}}
resizeMode="stretch"
/>
Run Code Online (Sandbox Code Playgroud)
https://snack.expo.io/rJCoC9S5-
我如何将图像宽度设为父级的25%,并将其高度设置为保持原始的width:height纵横比所需的高度?