gpt4 book ai didi

react-native - 居中容器而不是容器 RN 内的组件

转载 作者:行者123 更新时间:2023-12-04 15:23:27 54 4
gpt4 key购买 nike

我已应用正确的 css 属性使容器居中,但容器仍未居中。特别是 justifyContent 和 alignItems。我不想将里面的东西居中,而只是将容器居中。我怎样才能做到这一点?

function CardLesson({title, description}){
return <View style={styles.cardLesson}>
<LinearGradient
colors={['rgba(0,0,0,0.1)', 'transparent']}
style={{
position: 'absolute',
left: 0,
borderRadius: 10,
right: 0,
top: 0,
height: 10,
}}
/>
<Text style={styles.title}>{title}</Text>
<Text>{description}</Text>
</View>
}

cardLesson: {
flexDirection: 'column',
height: '30%',
borderRadius: 10,
marginVertical: 10,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'lightblue',
width: '80%',
}

enter image description here

最佳答案

Change your code like below, that solve your issue,

function CardLesson({title, description}){
return <View
style={{display:'flex',
alignItems: 'center',
justifyContent:'center'
}}>
<View style={styles.cardLesson}>
<LinearGradient
colors={['rgba(0,0,0,0.1)', 'transparent']}
style={{
position: 'absolute',
left: 0,
borderRadius: 10,
right: 0,
top: 0,
height: 10,
}}
/>
<Text style={styles.title}>{title}</Text>
<Text>{description}</Text>
</View>
</View>
}

cardLesson: {
flexDirection: 'column',
height: '30%',
borderRadius: 10,
marginVertical: 10,
backgroundColor: 'lightblue',
width: '80%',
}

关于react-native - 居中容器而不是容器 RN 内的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62828222/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com