【发布时间】:2018-02-04 02:05:12
【问题描述】:
我正在尝试在底部边框放置两个图像,每边的宽度为 50%,以便正确缩放到任何设备尺寸。但我似乎无法获得任何绝对定位来以可重现的方式表现。
我做了一个示例小吃:https://snack.expo.io/rJd3OkVIM
App 组件及相关样式如下所示:
import React, { Component } from 'react';
import { View, StyleSheet, Image } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Image
style={styles.img}
resizeMode="contain"
resizeMethod="resize"
source={require('./leftbg.png')}
/>
<Image
style={styles.imgr}
resizeMode="contain"
resizeMethod="resize"
source={require('./rightbg.png')}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
},
img: {
width: '50%',
position: 'absolute',
left: 0,
},
imgr: {
width: '50%',
position: 'absolute',
right: 0,
}
});
每个设备将图像垂直居中设置为屏幕的随机部分,每次打开项目时居中似乎都会改变。
【问题讨论】:
-
将高度设置为“100%”会有帮助吗?
-
不,这实际上会使图像垂直居中。
标签: react-native react-native-image