[英]Align Text Vertically in React Native
我想讓我的文字在圖片中變成這樣。 但我的文字沒有垂直居中。 如何實現?
到目前為止我所做的是
<Fragment>
<HeaderMain navigation={navigation}/>
<View style={styles.subheader}>
<Text style={styles.topText}>Заказы</Text>
</View>
</Fragment>
Styles
container: {
flex: 1,
paddingHorizontal: 8,
paddingVertical: 7,
backgroundColor: '#E5E5E5',
},
subheader:{
height: 55,
backgroundColor: '#ffffff',
flexDirection: 'column',
},
topText:{
fontWeight: "bold",
fontSize: 17,
lineHeight:21,
fontFamily: MONREGULAR,
marginLeft: 16,
justifyContent: 'center',
alignItems: 'center',
},
您不應該在Text
中使用justifyContent
和alignItems
。 您應該在View
中使用它。 還要給 lineHeight 與你的 fontSize 相同的值。 像這樣;
subheader:{
height: 55,
backgroundColor: '#ffffff',
flexDirection: 'column',
justifyContent: 'center',
},
topText:{
fontWeight: "bold",
fontSize: 17,
lineHeight: 21,
fontFamily: MONREGULAR,
marginLeft: 16,
},
試試這個子topText
應該是display:flex
和flex-direction:column
subheader
應該有justify-content:space-around
subheader:{
height: 55,
backgroundColor: '#ffffff',
flexDirection: 'column',
display: flex;
}
topText:{
fontWeight: "bold",
fontSize: 17,
lineHeight:21,
fontFamily: MONREGULAR,
marginLeft: 16,
justifyContent: 'space-around'
}
alignItems 和 justifyContent 用於調整視圖中的組件。 如果您想要的是將內容集中在您應該使用的文本中:textAlign,在您的情況下,我認為您應該使用:
textAlign: "center"
subheader:{
height: 55,
backgroundColor: '#ffffff',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
topText:{
fontWeight: "bold",
fontSize: 17,
lineHeight: 21,
fontFamily: MONREGULAR,
marginLeft: 16,
justifyContent: 'center',
alignItems: 'center',
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.