我想你想是這樣的:
組件/ index.js:
import React from 'react';
import {
View,
} from 'react-native';
import style from './style';
export default class Component extends React.Component {
render() {
return (
<View style={style.root}>
<View style={style.childOne} />
<View style={style.childTwo} />
</View>
);
}
}
組件/ style.js:
import { StyleSheet } from 'react-native';
export default StyleSheet.create({
root: {
flex: 1,
position: 'relative',
},
child1: {
...StyleSheet.absoluteFillObject,
},
child2: {
...StyleSheet.absoluteFillObject,
},
});
所以, View
with root
styl e將填充其父項的所有空間,因爲它具有flex: 1
。它有position: relative
,所以具有絕對定位的孩子會採取相應的行動。
View
s的child1
和child2
均具有絕對定位(StyleSheet.absoluteFillObject
爲{position: 'absolute', top: 0, right: 0, bottom: 0, left: 0}
docs here一個快捷方式)。 child1
和child2
將重疊並且child2
將會對child1
頂部,因爲其將在後面呈現。
絕對位置和z索引堆疊在彼此 – Li357
的俯視圖,你能後的你想什麼的屏幕截圖,另一個是你期待什麼呢? –