React-Native Text根据文字多少自动居中
首先要定义 Text 所在的View 的 justifyContent alignItems 设置居中,其次就是Text也要设置居中
export default class ViewStyleextends Component {
render(){
return(
<View style={selfStyle.miniView} >
<Text style={selfStyle.miniText}> 4 44444444444444</Text>
</View>
<View style={selfStyle.miniView}>
<Text style={selfStyle.miniText}>44 </Text>
</View>
);
}
}
const selfStyle =StyleSheet.create({
miniView:{
width :40,
height:40,
alignItems:'center',
justifyContent:'center',
},
miniText:{
margin :1.0,
fontSize:16,
color:'#FFFFFF',
textAlign :'center',
justifyContent:'center',
alignItems:'center',
},
},
)
网友评论