2017-03-14 44 views
0

請考慮下面的例子。絕對定位的View只會在其父級柔性框的邊界內呈現。ReactNative:無法佔用絕對定位的整個屏幕

<View style={{flex: 1}}> 
    <View style={{flex: 1}}> 
    <View style={{flex: 1}}> 
     <View style={{backgroundColor: 'red', position: 'absolute', top: 0, bottom: 0, left: 0, right: 0}}> 
     <Text>I am ABSOLUTE</Text> 
     </View> 
    </View> 
    <View style={{backgroundColor: 'blue', top: 50}}> 
     <View style={{margin: 10, padding: 10, height: 50}}> 
     <Text>I have a fixed height</Text> 
     </View> 
    </View> 
    </View> 
</View> 

PS。我正在使用RN 0.42.0。

+0

需要一個更好的示例。不知道你到底在找什麼。 – vinayr

+0

爲了重新創建,我不再注意到兩個平臺之間的區別。但上述情況仍然不如預期。絕對定位的視圖不應該佔據整個屏幕嗎? –

回答

1

absolute定位總是相對於父」
https://facebook.github.io/react-native/docs/layout-props.html#position

如果我需要與絕對定位的視圖,我想將其放置在根組件的底部。因此,根據您的示例,它看起來像 -

<View style={{flex: 1}}> 
    <View style={{flex: 1}}> 
    .... 
    </View> 
    <View style={{backgroundColor: 'red', position: 'absolute', top: 0, bottom: 0, left: 0, right: 0}}> 
    <Text>I am ABSOLUTE</Text> 
    </View> 
</View>