2017-01-22 7 views

답변

4

나는이 문제를 해결하기 위해 이것을 고안했다. enter image description here

JSX : 아래의 결과를 얻기 위해

<Image style={styles.universityImage} source={require('./csun.jpg')}> 
    <View style={styles.innerFrame}> 
     <Text style={styles.universityName}>California State University, Northridge</Text> 
     <Text style={styles.universityMotto}>"CSUN Shine"</Text> 
    </View> 
</Image> 

스타일 시트 :

const styles = StyleSheet.create({ 
// View tag styling 
innerFrame: { 
    flex: 1, 
    alignItems: 'center', 
    justifyContent: 'center', 
    backgroundColor: 'rgba(0, 0, 0, .5)', 
}, 
// Image tag styling 
universityImage: { 
    width: 300, 
    height: 250, 
    borderRadius: 5, 
}, 
universityName: { 
    color: '#fff', 
    opacity: .9, 
    fontSize: 20, 
    textAlign: 'center', 
    fontWeight: '500', 
    marginVertical: 15, 
    backgroundColor: 'transparent' 
}, 
universityMotto: { 
    color: '#fff', 
    opacity: .9, 
    textAlign: 'center', 
    backgroundColor: 'transparent' 
} 
}) 

과 중첩 <View></View><Image></Image> 내의 태그와 매우보기 태그 flex: 1 줄 그 전체 폭을 차지한다는 이 경우 <Image></Image> 태그 인 상위 태그의 높이입니다. 그런 다음 을 <View></View> 태그에 추가하여 불투명 한 모양으로 만듭니다. 그게 다야! 희망이 사람을 도와줍니다!

P. 중첩 된 <View></View> 태그 내에서 justifyContent: 'center', alignItems: 'center'으로 텍스트가 중간에 오도록했습니다

+0

RN의 이미지 구성 요소 안에 하위 구성 요소 (보기)를 넣을 수 없다는 오류가 발생합니다. . – SpicyClubSauce