2017-04-07 68 views
0

我以前使用的是Android相對佈局,做了很多:無本機:地方觀看婁另一箇中心的觀點

+-----------+ 
|   |<- parent view 
|   | 
| +-----+ | 
| |  | <--- centered 
| |  | | child view 
| +-----+ | 
| [XXX] <---- view positioned 
|   | bellow centered 
+-----------+ child view 

是否有可能實現反應母語一樣嗎?

回答

1

我做了類似今天這樣的:

   <View style={{ flex: 1 }}> 
        <View style={{ 
         height: 350, 
         backgroundColor: "blue" 
        }}> 

        <View style={{ 
         backgroundColor: "red", 
         height: 100, 
         width: 100, 
         position: "absolute", 
         top: "50%", 
         left: "50%", 
         marginLeft: -50, // Half the width of this child 
         marginTop: -50 // Half the height of this child 
        }}> 
         <Text>Hello...</Text> 
        </View> 

        <View style={{ 
         backgroundColor: "green", 
         height: 30, 
         width: 100, 
         position: "absolute", 
         top: "50%", 
         left: "50%", 
         marginLeft: -50, // Half the width of this child 
         marginTop: 70 // This just controls how far down from center this child is 
        }}> 
         <Text>...world</Text> 
        </View> 
       </View> 

但這也需要你知道父裏面的元件的尺寸,不過這樣你就可以正確設置對孩子的marginLeft和marginTop值。