KD.*_*KD. 5 react-native react-native-flexbox
这是一个要实现的示例,下面是组件结构的细分
<View style={styles.buttonHolder}>
<Text style={styles.greenButtonIcon}>
FB
</Text>
<Text style={styles.greenButtonText}>
{this.props.buttonName}
</Text>
</View>
Run Code Online (Sandbox Code Playgroud)
我的问题在这里,因为文本与整个框居中对齐,所以我无法为文本和图标提供弹性值,因为那样会使它们具有自己的空间并且不会浮动。
你能帮忙吗?如果需要更多信息,请告诉我。
尝试将它们放在buttonHolder. 设置buttonHolder为justifyContent并alignItems居中。然后将绿色按钮设置alignSelf为flex-start:
<View style={styles.buttonHolder}>
<View style={styles.absolute}>
<Text style={styles.greenButtonIcon}>
FB
</Text>
</View>
<View style={styles.absolute}>
<Text style={styles.greenButtonText}>
{this.props.buttonName}
</Text>
</View>
</View>
const styles = StyleSheet.create({
absolute: {
position: 'absolute',
height: '100%',
width: '100%',
alignContent: 'center',
justifyContent: 'center'
},
styles.greenButtonIcon: {
alignSelf: 'flex-start'
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1856 次 |
| 最近记录: |