我试图在底部边框放置两个图像,每边的宽度为 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,
}
});
每个设备将图像垂直居中设置为屏幕的随机部分,每次打开项目时,居中似乎都会发生变化。