2017-09-06 34 views
0

我想要寫的樣式表來顯示這樣的圖像一個loyout:反應的其它視圖的本機映像前

化身:

avatar

我寫這樣的代碼:

<View style={styles.header}></View> 
<View style={styles.meInfor}> 
    <Image style={styles.avatar} 
     source={require('../../images/cristiano-ronaldo.jpg')} /> 
</View> 

and style:

header:{ 
     width: width, 
     height: 100, 
     backgroundColor: '#1270BA', 
    }, 
    meInfor:{ 
     width: width, 
     backgroundColor: '#FFFFFF', 
     alignItems: 'center', 
     justifyContent: 'center', 
    }, 
    avatar: { 
     marginTop: -50, 
     width: 100, 
     height: 100, 
     borderRadius: 100, 
    } 

我用marginTop: - 50拉頭像頂部,但結果是這樣的:

壞的結果:

bad result

我該怎麼做才能樣式這將化身像第一個圖像?

+0

嘗試使用位置:「絕對」阿凡達 –

+0

我加入這個屬性和隱藏的頭像。 :( –

+0

由兩個柄圖像去除餘量也 –

回答

0

this the result of the code

試試這個代碼,它在我的情況下

組件

import React, { Component } from 'react'; 
import { Text, Image, View, StyleSheet, Dimensions } from 'react-native'; 


export default class App extends Component { 
    render() { 
    const {header, meInfor, avatar, container} = styles; 
    return (
     <View style={container}> 
     <View style={header}></View> 
     <View style={meInfor}></View> 
     <Image style={avatar} 
     source={{uri: 'http://infosahabat.com/wp-content/uploads/2015/12/Permainan-Bola-Besar.jpg'}} 
     /> 
     </View> 
    ); 
    } 
} 

運行良好而本作的風格

風格

const styles = StyleSheet.create({ 
    container: { 
     flex: 1, 
     backgroundColor: 'lightgray', 
    }, 
    header:{ 
     height: 100, 
     backgroundColor: '#1270BA', 
    }, 
    meInfor:{ 
     backgroundColor: '#FFF', 
     top: 0, 
     height: 50, 
     width: (Dimensions.get('window').width), 
    }, 
    avatar: { 
     position: 'absolute', 
     top: 50, 
     left: (Dimensions.get('window').width/2) - 50, 
     alignItems: 'center', 
     width: 100, 
     height: 100, 
     borderColor: 'black', 
     borderWidth: 1, 
     borderRadius: 100, 
    } 
}); 
+0

我想要'meInfor' width ='Dimensions.get('window')。width'。並且只有頭像上的邊框半徑曲線,而不是正方形。 –

+0

我已更新我的代碼https://repl.it/KkQ9/5嘗試檢查它是否像你想要的 –

0

更改樣式表這樣

header : { 
     width: width, 
     height: 100, 
     backgroundColor: '#1270BA' 
    }, 
    meInfor : { 
     position: 'absolute', 

     width: width, 

     alignItems: 'center', 
     justifyContent: 'center' 
    }, 
    avatar : { 
     marginTop: 50, 
     width: 100, 
     height: 100, 
     borderRadius: 100 
    } 
+0

謝謝你,但我不行。我招。糾正結果 –

+0

你有上述父視圖內的兩個觀點包裹 –

+0

YEB,他們裹着通過容器視圖: 容器:{ \t \t柔性:1, \t \t alignItems: '中心', \t \t justifyContent: 'flex-start', \t}, –