绝对坐标absolute
- 相对于父节点的4个角落,通过left、right、top、bottom来调整相对于父窗口的坐标
<View style={[styles.circle, {position: 'absolute', bottom: 0, right: 0}]} />
当left、right同时存在时,left会覆盖right的属性
同理top和bottom同时存在时,top会覆盖bottom的坐标属性绝对坐标是相对于父节点的,而不是相对于根节点的
<View style={{flex: 1, backgroundColor: 'gray'}}>
<View style={{height: 100, backgroundColor: 'green'}}>
<View style={[styles.circle, {position: 'absolute', bottom: 0, right: 0}]}/>
</View>
</View>
相对坐标relative
- relative坐标是默认坐标,
position: 'relative'
默认是添加的
<View style={{ flex: 1, backgroundColor: 'gray' }}>
<View style={{ height: 100, backgroundColor: 'green'}}>
<View style={[styles.circle, {position: 'relative', left: 0, top: 0 }]} />
<View style={[styles.circle, {position: 'relative', left: 0, top: 0 }]} />
</View>
</View>